JDK-8149335 : VerifyError with java/io/PrintStream println()
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 8u74
  • Priority: P3
  • Status: Resolved
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2016-02-06
  • Updated: 2016-03-02
  • Resolved: 2016-03-02
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
$ java -version
java version "1.8.0_74"
Java(TM) SE Runtime Environment (build 1.8.0_74-b02)
Java HotSpot(TM) 64-Bit Server VM (build 25.74-b02, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
mac os x 10.9.5
uname -a
Darwin  13.4.0 Darwin Kernel Version 13.4.0: Wed Mar 18 16:20:14 PDT 2015; root:xnu-2422.115.14~1/RELEASE_X86_64 x86_64

EXTRA RELEVANT SYSTEM CONFIGURATION :
macbook pro 15-inch, Early 2011
processor: 2.3 Ghz Intel Core i7
memory: 8 GB 1333 MHz DDR3

A DESCRIPTION OF THE PROBLEM :
Receiving exception java.lang.VerifyError.  I've included a simple program that causes the Exception on my mac.  I've run it on my linux box and it works fine.

REGRESSION.  Last worked in version 6u45

ADDITIONAL REGRESSION INFORMATION: 
The code worked on Mac OS X 10.6.8 with Java 1.6 although I cant remember the exact version number, I just selected one of the Java 1.6 entries from the drop down above.
current output from java -version:

java version "1.8.0_74"
Java(TM) SE Runtime Environment (build 1.8.0_74-b02)
Java HotSpot(TM) 64-Bit Server VM (build 25.74-b02, mixed mode)

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
javac TestVerifyError.java
java TestVerifyError

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The output from the compiled program should be:
 
No Data Found
ACTUAL -
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.VerifyError: Bad local variable type
Exception Details:
  Location:
    TestVerifyError.main([Ljava/lang/String;)V @36: aload_1
  Reason:
    Type top (current frame, locals[1]) is not assignable to reference type
  Current Frame:
    bci: @36
    flags: { }
    locals: { '[Ljava/lang/String;', top, '[Ljava/lang/String;', 'java/io/PrintStream' }
    stack: { 'java/io/PrintStream' }
  Bytecode:
    0x0000000: 04bd 0002 4d2c 0301 53bb 0003 59b2 0004
    0x0000010: 0412 05b7 0006 4e2d 2c03 32c6 0009 2c03
    0x0000020: 32a7 0004 2bb6 0007 a700 213a 04bb 0009
    0x0000030: 59bb 000a 59b7 000b 120c b600 0d19 04b6
    0x0000040: 000e b600 0fb7 0010 bfb1               
  Exception Handler Table:
    bci [9, 40] => handler: 43
  Stackmap Table:
    full_frame(@36,{Object[#26],Top,Object[#26],Object[#27]},{Object[#27]})
    full_frame(@37,{Object[#26],Top,Object[#26],Object[#27]},{Object[#27],Object[#28]})
    full_frame(@43,{Object[#26],Top,Object[#26]},{Object[#29]})
    append_frame(@73,Object[#27])

	at java.lang.Class.getDeclaredMethods0(Native Method)
	at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
	at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
	at java.lang.Class.getMethod0(Class.java:3018)
	at java.lang.Class.getMethod(Class.java:1784)
	at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
	at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)

ERROR MESSAGES/STACK TRACES THAT OCCUR :
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.VerifyError: Bad local variable type
Exception Details:
  Location:
    TestVerifyError.main([Ljava/lang/String;)V @36: aload_1
  Reason:
    Type top (current frame, locals[1]) is not assignable to reference type
  Current Frame:
    bci: @36
    flags: { }
    locals: { '[Ljava/lang/String;', top, '[Ljava/lang/String;', 'java/io/PrintStream' }
    stack: { 'java/io/PrintStream' }
  Bytecode:
    0x0000000: 04bd 0002 4d2c 0301 53bb 0003 59b2 0004
    0x0000010: 0412 05b7 0006 4e2d 2c03 32c6 0009 2c03
    0x0000020: 32a7 0004 2bb6 0007 a700 213a 04bb 0009
    0x0000030: 59bb 000a 59b7 000b 120c b600 0d19 04b6
    0x0000040: 000e b600 0fb7 0010 bfb1               
  Exception Handler Table:
    bci [9, 40] => handler: 43
  Stackmap Table:
    full_frame(@36,{Object[#26],Top,Object[#26],Object[#27]},{Object[#27]})
    full_frame(@37,{Object[#26],Top,Object[#26],Object[#27]},{Object[#27],Object[#28]})
    full_frame(@43,{Object[#26],Top,Object[#26]},{Object[#29]})
    append_frame(@73,Object[#27])

	at java.lang.Class.getDeclaredMethods0(Native Method)
	at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
	at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
	at java.lang.Class.getMethod0(Class.java:3018)
	at java.lang.Class.getMethod(Class.java:1784)
	at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
	at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.io.PrintStream;


public class TestVerifyError {

  public static void main( String argv[] ){

    final String ndf = "No Data Found";
    final String displayText[] = new String[1];
    final PrintStream out;
    displayText[0] = null;

    try {
        out = new PrintStream( System.out, true, "UTF-8" );
        // out.println();
        out.println((displayText[0] != null) ? displayText[0] : ndf);
    }
    catch ( java.io.UnsupportedEncodingException e ){
        throw new RuntimeException(
            "error creating UTF-8 print stream. " + e );
    }
  }
}
---------- END SOURCE ----------


Comments
Duplicate bug. JDK8 backport will be created for the linked bug. (https://bugs.openjdk.java.net/browse/JDK-8066871)
02-03-2016

This bug is indeed duplicate of https://bugs.openjdk.java.net/browse/JDK-8066871 I will be closing this bug as duplicate and create a backport of the linked bug for jdk8.
02-03-2016

Additional Findings about this bug: 1. This issue is generic, not platform dependent. 2. This issue can be reproduced always on any platform. Tried on Windows and Ubuntu using command prompt and Terminal respectively. 3. This issue is not seen when javac is run in debug mode. (using "-g" option). 4. This bug cannot be reproduced on any IDEs (Netbeans, Eclipse) and the reason should be point 3.(looks like IDEs compile code using -g by default though it can be disabled in the project properties to reproduce this issue). Also, I have reduced the test case to reproduce this issue as below: import java.io.PrintStream; public class TestPrintStreamVerifyError { public static void main(String argv[]) { final String ndf = "No Data Found"; String displayText = null; System.out.println((null != displayText) ? displayText : ndf); } }
01-03-2016

I am able to reproduce this bug on Ubuntu 14.04 LTS This issue is introduced in 1.8.0 build b66.
26-02-2016

javac in 1.8.0_75-ea generates the following which causes a VerifyError at the aload_1 because locals[1], 'bogus',is not a reference. http://docs.oracle.com/javase/specs/jvms/se8/html/jvms-6.html#jvms-6.5.aload_n: " The local variable at <n> must contain a reference" L36: stack_frame_type full; locals_map class "[Ljava/lang/String;", bogus, class "[Ljava/lang/String;", class java/io/PrintStream; stack_map class java/io/PrintStream; aload_1; L37: stack_frame_type full; locals_map class "[Ljava/lang/String;", bogus, class "[Ljava/lang/String;", class java/io/PrintStream; stack_map class java/io/PrintStream, class java/lang/String; invokevirtual Method java/io/PrintStream.println:"(Ljava/lang/String;)V"; endtry t0; In JDK-9, javac generates code that does not cause a VerifyError: L36: stack_frame_type full; locals_map class "[Ljava/lang/String;", bogus, class "[Ljava/lang/String;", class java/io/PrintStream; stack_map class java/io/PrintStream; ldc String "No Data Found"; L38: stack_frame_type full; locals_map class "[Ljava/lang/String;", bogus, class "[Ljava/lang/String;", class java/io/PrintStream; stack_map class java/io/PrintStream, class java/lang/String; invokevirtual Method java/io/PrintStream.println:"(Ljava/lang/String;)V"; endtry t0;
08-02-2016

The test passes on Windows and linux, fails only on osx . Tried the attached test case with following JDK versions: JDK 7u80 - Pass JDK 1.8.0 - Fail JDK 8u74 - Fail JDK 8u76 - Fail JDK 9 - Pass Following is the output in failed versions: Exception in thread "main" java.lang.VerifyError: Bad local variable type Exception Details: Location: JI9029287.main([Ljava/lang/String;)V @36: aload_1 Reason: Type top (current frame, locals[1]) is not assignable to reference type Current Frame: bci: @36 flags: { } locals: { '[Ljava/lang/String;', top, '[Ljava/lang/String;', 'java/io/PrintS tream' } stack: { 'java/io/PrintStream' } Bytecode: 0000000: 04bd 0002 4d2c 0301 53bb 0003 59b2 0004 0000010: 0412 05b7 0006 4e2d 2c03 32c6 0009 2c03 0000020: 32a7 0004 2bb6 0007 a700 213a 04bb 0009 0000030: 59bb 000a 59b7 000b 120c b600 0d19 04b6 0000040: 000e b600 0fb7 0010 bfb1 Exception Handler Table: bci [9, 40] => handler: 43 Stackmap Table: full_frame(@36,{Object[#26],Top,Object[#26],Object[#27]},{Object[#27]}) full_frame(@37,{Object[#26],Top,Object[#26],Object[#27]},{Object[#27],Object [#28]}) full_frame(@43,{Object[#26],Top,Object[#26]},{Object[#29]}) append_frame(@73,Object[#27]) at java.lang.Class.getDeclaredMethods0(Native Method) at java.lang.Class.privateGetDeclaredMethods(Class.java:2688) at java.lang.Class.getMethod0(Class.java:2937) at java.lang.Class.getMethod(Class.java:1771) at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544 ) at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
08-02-2016