diff options
author | Liam Miller-Cushon <cushon@google.com> | 2021-12-07 20:57:09 -0800 |
---|---|---|
committer | Javac Team <javac-team+copybara@google.com> | 2021-12-07 20:57:45 -0800 |
commit | 08ff1a11e0ea097b7bd1624084cac7f6f4c5d9b8 (patch) | |
tree | 577b3924f8a8bccf54d00fdb3a22f067b44a8c0f | |
parent | 972d62a80cd12dab2362ac2a71282ec56264f4e3 (diff) | |
download | turbine-08ff1a11e0ea097b7bd1624084cac7f6f4c5d9b8.tar.gz |
Don't crash on constant dynamic constant pool entries
PiperOrigin-RevId: 414898023
-rw-r--r-- | java/com/google/turbine/bytecode/ConstantPoolReader.java | 2 | ||||
-rw-r--r-- | javatests/com/google/turbine/bytecode/ClassReaderTest.java | 13 |
2 files changed, 15 insertions, 0 deletions
diff --git a/java/com/google/turbine/bytecode/ConstantPoolReader.java b/java/com/google/turbine/bytecode/ConstantPoolReader.java index ffcb4c3..d00ee22 100644 --- a/java/com/google/turbine/bytecode/ConstantPoolReader.java +++ b/java/com/google/turbine/bytecode/ConstantPoolReader.java @@ -36,6 +36,7 @@ public class ConstantPoolReader { static final int CONSTANT_UTF8 = 1; static final int CONSTANT_METHOD_HANDLE = 15; static final int CONSTANT_METHOD_TYPE = 16; + static final int CONSTANT_DYNAMIC = 17; static final int CONSTANT_INVOKE_DYNAMIC = 18; static final int CONSTANT_MODULE = 19; static final int CONSTANT_PACKAGE = 20; @@ -88,6 +89,7 @@ public class ConstantPoolReader { case CONSTANT_INTEGER: case CONSTANT_FLOAT: case CONSTANT_NAME_AND_TYPE: + case CONSTANT_DYNAMIC: case CONSTANT_INVOKE_DYNAMIC: reader.skip(4); return 1; diff --git a/javatests/com/google/turbine/bytecode/ClassReaderTest.java b/javatests/com/google/turbine/bytecode/ClassReaderTest.java index 9a9fdb1..ad5b90d 100644 --- a/javatests/com/google/turbine/bytecode/ClassReaderTest.java +++ b/javatests/com/google/turbine/bytecode/ClassReaderTest.java @@ -39,6 +39,7 @@ import org.objectweb.asm.Attribute; import org.objectweb.asm.ByteVector; import org.objectweb.asm.ClassWriter; import org.objectweb.asm.FieldVisitor; +import org.objectweb.asm.Handle; import org.objectweb.asm.ModuleVisitor; import org.objectweb.asm.Opcodes; @@ -236,6 +237,18 @@ public class ClassReaderTest { } @Test + public void condy() { + ClassWriter cw = new ClassWriter(0); + cw.visit(52, Opcodes.ACC_SUPER, "Test", null, "java/lang/Object", null); + cw.newConstantDynamic( + "f", "Ljava/lang/String;", new Handle(Opcodes.H_INVOKESTATIC, "A", "f", "()V", false)); + byte[] bytes = cw.toByteArray(); + + ClassFile cf = ClassReader.read(null, bytes); + assertThat(cf.name()).isEqualTo("Test"); + } + + @Test public void v53() { ClassWriter cw = new ClassWriter(0); cw.visitAnnotation("Ljava/lang/Deprecated;", true); |