Duplicate :
|
|
Relates :
|
|
Relates :
|
|
Relates :
|
|
Relates :
|
JDK-8249970 :
|
FULL PRODUCT VERSION : java version "1.8.0_65" Java(TM) SE Runtime Environment (build 1.8.0_65-b17) Java HotSpot(TM) 64-Bit Server VM (build 25.65-b01, mixed mode) FULL OS VERSION : Microsoft Windows [Version 6.1.7601] A DESCRIPTION OF THE PROBLEM : Constant pool entries of type "class" with class name "LClassName;" (without quotes) are interpreted by JVM as a reference to the class "ClassName". Here is an excerpt from constant pool as reported by javap: #15 = Utf8 LBadHelloWorld; #16 = Class #15 // "LBadHelloWorld;" The bytecode instruction 0: new #16 // class "LBadHelloWorld;" will actually instantiate class with name "BadHelloWorld". THE PROBLEM WAS REPRODUCIBLE WITH -Xint FLAG: Yes THE PROBLEM WAS REPRODUCIBLE WITH -server FLAG: Yes STEPS TO FOLLOW TO REPRODUCE THE PROBLEM : Compile and run generator class that will generate problematic *.class file. See "Source code for an executable test case" field below for generator source. EXPECTED VERSUS ACTUAL BEHAVIOR : Expected: - Some kind of verification and/or runtime error, probably "NoClassDefFoundError". Actual: - Generated sample class file run without any visible problems. REPRODUCIBILITY : This bug can be reproduced always. ---------- BEGIN SOURCE ---------- // // !!! The ASM 5.x (http://asm.ow2.org/) library MUST be available in class path to compile and run the following code! // import java.util.*; import java.io.OutputStream; import java.nio.file.Files; import java.nio.file.Paths; import org.objectweb.asm.*; public class HelloWorldGen implements Opcodes { public static String GENERATED_CLASS_NAME = "BadHelloWorld"; public static byte[] dump () throws Exception { ClassWriter cw = new ClassWriter(0); FieldVisitor fv; MethodVisitor mv; AnnotationVisitor av0; cw.visit(52, ACC_PUBLIC + ACC_SUPER, GENERATED_CLASS_NAME, null, "java/lang/Object", null); { mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); mv.visitInsn(RETURN); mv.visitMaxs(1, 1); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "toString", "()Ljava/lang/String;", null, null); mv.visitCode(); mv.visitLdcInsn("Hello, world!"); mv.visitInsn(ARETURN); mv.visitMaxs(1, 1); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC + ACC_VARARGS, "main", "([Ljava/lang/String;)V", null, null); mv.visitCode(); mv.visitTypeInsn(NEW, "L" + GENERATED_CLASS_NAME + ";"); mv.visitInsn(DUP); mv.visitMethodInsn(INVOKESPECIAL, "L" + GENERATED_CLASS_NAME + ";", "<init>", "()V", false); mv.visitVarInsn(ASTORE, 1); mv.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;"); mv.visitVarInsn(ALOAD, 1); mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/Object;)V", false); mv.visitInsn(RETURN); mv.visitMaxs(2, 2); mv.visitEnd(); } cw.visitEnd(); return cw.toByteArray(); } public static void main(String... args) throws Exception { try (OutputStream out = Files.newOutputStream(Paths.get(GENERATED_CLASS_NAME + ".class"));) { out.write(dump()); } } } ---------- END SOURCE ----------
|