Commit a0cee8eb authored by Remi Forax's avatar Remi Forax
Browse files

fix all issues raised by the review

parent 4f86448a
......@@ -116,11 +116,10 @@ public class CheckModuleAdapter extends ModuleVisitor {
| Opcodes.ACC_TRANSITIVE
| Opcodes.ACC_SYNTHETIC
| Opcodes.ACC_MANDATED);
if (classVersion >= Opcodes.V10 && module.equals("java.base")) {
if ((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");
}
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();
}
}
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;
/**
* Tests for issue #317804.
*
* @author Remi Forax
*/
public class Issue317804Test {
@Test
public void testTransitive() {
CheckClassAdapter adapter = new CheckClassAdapter(null, false);
adapter.visit(Opcodes.V10, Opcodes.ACC_PUBLIC, "module-info", null, null, null);
ModuleVisitor mv = adapter.visitModule("org.objectweb.asm", 0, null);
assertThrows(IllegalArgumentException.class, () -> mv.visitRequire("java.base", Opcodes.ACC_TRANSITIVE, null));
}
@Test
public void testStaticPhase() {
CheckClassAdapter adapter = new CheckClassAdapter(null, false);
adapter.visit(Opcodes.V10, Opcodes.ACC_PUBLIC, "module-info", null, null, null);
ModuleVisitor mv = adapter.visitModule("org.objectweb.asm", 0, null);
assertThrows(IllegalArgumentException.class, () -> mv.visitRequire("java.base", Opcodes.ACC_STATIC_PHASE, null));
}
@Test
public void testBoth() {
CheckClassAdapter adapter = new CheckClassAdapter(null, false);
adapter.visit(Opcodes.V10, Opcodes.ACC_PUBLIC, "module-info", null, null, null);
ModuleVisitor mv = adapter.visitModule("org.objectweb.asm", 0, null);
assertThrows(IllegalArgumentException.class, () -> mv.visitRequire("java.base", Opcodes.ACC_TRANSITIVE | Opcodes.ACC_STATIC_PHASE, null));
}
@Test
public void testTransitiveOrStaticPhaseAreIgnoredUnderJVMS9() {
CheckClassAdapter adapter = new CheckClassAdapter(null, false);
adapter.visit(Opcodes.V9, Opcodes.ACC_PUBLIC, "module-info", null, null, null);
ModuleVisitor mv = adapter.visitModule("org.objectweb.asm", 0, null);
mv.visitRequire("java.base", Opcodes.ACC_TRANSITIVE | Opcodes.ACC_STATIC_PHASE, null);
mv.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