Commit 3cee35fc authored by Remi Forax's avatar Remi Forax

Merge branch '317804-unit-test' into 'master'

The JVMS 10 does not allow to require 'java.base' with ACC_TRANSIVE or ACC_STATIC_PHASE

Closes #317804

See merge request !88
parents 61c8ff9e a0cee8eb
......@@ -403,8 +403,10 @@ public class CheckClassAdapter extends ClassVisitor {
visitModuleCalled = true;
checkFullyQualifiedName(name, "module name");
checkAccess(access, Opcodes.ACC_OPEN | Opcodes.ACC_SYNTHETIC | Opcodes.ACC_MANDATED);
return new CheckModuleAdapter(
CheckModuleAdapter checkModuleAdapter = new CheckModuleAdapter(
api, super.visitModule(name, access, version), (access & Opcodes.ACC_OPEN) != 0);
checkModuleAdapter.classVersion = this.version;
return checkModuleAdapter;
}
@Override
......
......@@ -38,7 +38,6 @@ import org.objectweb.asm.Opcodes;
* @author Remi Forax
*/
public class CheckModuleAdapter extends ModuleVisitor {
/** Whether the visited module is open. */
private final boolean isOpen;
......@@ -57,6 +56,9 @@ public class CheckModuleAdapter extends ModuleVisitor {
/** The internal names of the services provided by the visited module. */
private final HashSet<String> providedServices = new HashSet<String>();
/** The class version number. */
int classVersion;
/** Whether the {@link #visitEnd} method has been called. */
private boolean visitEndCalled;
......@@ -114,6 +116,11 @@ public class CheckModuleAdapter extends ModuleVisitor {
| Opcodes.ACC_TRANSITIVE
| Opcodes.ACC_SYNTHETIC
| Opcodes.ACC_MANDATED);
if (classVersion >= Opcodes.V10 && module.equals("java.base") &&
(access & (Opcodes.ACC_STATIC_PHASE | Opcodes.ACC_TRANSITIVE)) != 0) {
throw new IllegalArgumentException("Invalid access flags: " + access +
" java.base can not be declared ACC_TRANSITIVE or ACC_STATIC_PHASE");
}
super.visitRequire(module, access, version);
}
......
......@@ -30,6 +30,8 @@ package org.objectweb.asm.util;
import static org.junit.jupiter.api.Assertions.assertThrows;
import org.junit.jupiter.api.Test;
import org.objectweb.asm.ModuleVisitor;
import org.objectweb.asm.Opcodes;
/**
* CheckModuleAdapter tests.
......@@ -77,4 +79,38 @@ public class CheckModuleAdapterTest {
checkModuleAdapter.visitEnd();
assertThrows(RuntimeException.class, () -> checkModuleAdapter.visitUse("service"));
}
@Test // see issue #317804
public void testRequireJavaBaseTransitive() {
CheckClassAdapter adapter = new CheckClassAdapter(null, false);
adapter.visit(Opcodes.V10, Opcodes.ACC_PUBLIC, "module-info", null, null, null);
ModuleVisitor moduleVisitor = adapter.visitModule("org.objectweb.asm", 0, null);
assertThrows(IllegalArgumentException.class, () -> moduleVisitor.visitRequire("java.base", Opcodes.ACC_TRANSITIVE, null));
}
@Test // see issue #317804
public void testRequireJavaBaseStaticPhase() {
CheckClassAdapter adapter = new CheckClassAdapter(null, false);
adapter.visit(Opcodes.V10, Opcodes.ACC_PUBLIC, "module-info", null, null, null);
ModuleVisitor moduleVisitor = adapter.visitModule("org.objectweb.asm", 0, null);
assertThrows(IllegalArgumentException.class, () -> moduleVisitor.visitRequire("java.base", Opcodes.ACC_STATIC_PHASE, null));
}
@Test // see issue #317804
public void testRequireJavaBaseTransitiveAndStaticPhase() {
CheckClassAdapter adapter = new CheckClassAdapter(null, false);
adapter.visit(Opcodes.V10, Opcodes.ACC_PUBLIC, "module-info", null, null, null);
ModuleVisitor moduleVisitor = adapter.visitModule("org.objectweb.asm", 0, null);
assertThrows(IllegalArgumentException.class, () -> moduleVisitor.visitRequire("java.base", Opcodes.ACC_TRANSITIVE | Opcodes.ACC_STATIC_PHASE, null));
}
@Test // see issue #317804
public void testRequireJavaBaseTransitiveOrStaticPhaseAreIgnoredUnderJVMS9() {
CheckClassAdapter adapter = new CheckClassAdapter(null, false);
adapter.visit(Opcodes.V9, Opcodes.ACC_PUBLIC, "module-info", null, null, null);
ModuleVisitor moduleVisitor = adapter.visitModule("org.objectweb.asm", 0, null);
moduleVisitor.visitRequire("java.base", Opcodes.ACC_TRANSITIVE | Opcodes.ACC_STATIC_PHASE, null);
moduleVisitor.visitEnd();
adapter.visitEnd();
}
}
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