Commit 46239d97 authored by Eric Bruneton's avatar Eric Bruneton
Browse files

Allow private or protected access flags for inner classes.

parent 5495d4d1
Pipeline #13252 passed with stage
in 6 minutes and 13 seconds
......@@ -215,8 +215,7 @@ public class CheckClassAdapter extends ClassVisitor {
}
visitCalled = true;
checkState();
checkAccess(
access,
int validAccessFlags =
Opcodes.ACC_PUBLIC
| Opcodes.ACC_FINAL
| Opcodes.ACC_SUPER
......@@ -227,10 +226,14 @@ public class CheckClassAdapter extends ClassVisitor {
| Opcodes.ACC_ENUM
| Opcodes.ACC_DEPRECATED
| Opcodes.ACC_RECORD
| Opcodes.ACC_MODULE);
| Opcodes.ACC_MODULE;
if (name == null) {
throw new IllegalArgumentException("Illegal class name (null)");
}
if (name.contains("$")) {
validAccessFlags |= Opcodes.ACC_PROTECTED | Opcodes.ACC_PRIVATE;
}
checkAccess(access, validAccessFlags);
if (!name.endsWith("package-info") && !name.endsWith("module-info")) {
CheckMethodAdapter.checkInternalName(version, name, "class name");
}
......
......@@ -6,13 +6,13 @@
// modification, are permitted provided that the following conditions
// are met:
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// 3. Neither the name of the copyright holders nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
......@@ -78,6 +78,30 @@ public class CheckClassAdapterTest extends AsmTest implements Opcodes {
assertEquals("Invalid access flags: 1048576", exception.getMessage());
}
@Test
public void testVisit_illegalPrivateClassAccessFlagForNonInnerClass() {
CheckClassAdapter checkClassAdapter = new CheckClassAdapter(null);
Executable visit =
() ->
checkClassAdapter.visit(V1_1, Opcodes.ACC_PRIVATE, "C", null, "java/lang/Object", null);
Exception exception = assertThrows(IllegalArgumentException.class, visit);
assertEquals("Invalid access flags: 2", exception.getMessage());
}
@Test
public void testVisit_legalPrivateClassAccessFlagForInnerClass() {
CheckClassAdapter checkClassAdapter = new CheckClassAdapter(null);
Executable visit =
() ->
checkClassAdapter.visit(
V1_1, Opcodes.ACC_PRIVATE, "C$Inner", null, "java/lang/Object", null);
assertDoesNotThrow(visit);
}
@Test
public void testVisit_illegalClassName() {
CheckClassAdapter checkClassAdapter = new CheckClassAdapter(null);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment