Commit 498ac5c0 authored by Eric Bruneton's avatar Eric Bruneton
Browse files

Add failing tests showing the issue.

parent b14e3c29
......@@ -31,6 +31,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.jupiter.params.provider.ValueSource;
import org.objectweb.asm.test.AsmTest;
......@@ -122,6 +123,40 @@ public class ClassVisitorTest extends AsmTest {
* Tests that a ClassReader -> class adapter -> ClassWriter chain give the same result with or
* without the copy pool option, when the class version is changed (and optionally a synthetic
* attribute as well).
@CsvSource({"true, true", "true, false", "false, true", "false, false"})
public void testReadAndWriteWithCopyPoolAndSyntheticAdapter(
final boolean upgradeVersion, final boolean changeSynthetic) {
ClassWriter sourceClassWriter = new ClassWriter(0);
upgradeVersion ? Opcodes.V1_4 : Opcodes.V1_5,
.visitMethod(Opcodes.ACC_ABSTRACT | Opcodes.ACC_SYNTHETIC, "m", "()V", null, null)
ClassReader classReader = new ClassReader(sourceClassWriter.toByteArray());
ClassWriter classWriter = new ClassWriter(0);
ClassWriter copyPoolClassWriter = new ClassWriter(classReader, 0);
int version = upgradeVersion ? Opcodes.V1_5 : Opcodes.V1_4;
int access = changeSynthetic ? Opcodes.ACC_SYNTHETIC : 0;
new ChangeVersionAdapter(new ChangeAccessAdapter(classWriter, access), version), 0);
new ChangeVersionAdapter(new ChangeAccessAdapter(copyPoolClassWriter, access), version), 0);
/** Test that classes with only visible or only invisible annotations can be read correctly. */
@ValueSource(strings = {"true", "false"})
......@@ -317,6 +352,27 @@ public class ClassVisitorTest extends AsmTest {
private static class ChangeVersionAdapter extends ClassVisitor {
private final int newVersion;
ChangeVersionAdapter(final ClassVisitor classVisitor, final int newVersion) {
super(Opcodes.ASM6, classVisitor);
this.newVersion = newVersion;
public void visit(
final int version,
final int access,
final String name,
final String signature,
final String superName,
final String[] interfaces) {
super.visit(newVersion, access, name, signature, superName, interfaces);
private static class ChangeAccessAdapter extends ClassVisitor {
private final int accessFlags;
Supports Markdown
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