Community
Participate
Working Groups
Build R2.1 The following code will not verify if compiled in mode where unused locals are optimized out: public class X { public static void main(String[] argv){ int i; assert argv != null || true : i; System.out.println("SUCCESS"); } } START RUNNING--------------------------------------------------- java.lang.VerifyError: (class: X, method: main signature: ([Ljava/lang/String;) V) Illegal local variable number at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:140) at Compile.main(Compile.java:28) DONE RUNNING---------------------------------------------------- DISASSEMBLING-------------------------------------------------- /* * Version (target 1.4) * - magic: CAFEBABE * - minor: 0 * - major: 48 */ // Compiled from X.java public class X extends java.lang.Object { final static boolean $assertionsDisabled; Attribute: Name: Synthetic Length: 0 /* Field descriptor #6 Z */ static java.lang.Class class$0; Attribute: Name: Synthetic Length: 0 /* Field descriptor #9 Ljava/lang/Class; */ /* Method descriptor #11 ()V */ static {}; /* Stack: 3, Locals: 0 */ Code attribute: 0 getstatic #14 <Field X#class$0 java.lang.Class> 3 dup 4 ifnonnull 32 7 pop 8 ldc #15 <String "X"> 10 invokestatic #21 <Method java.lang.Class#forName(java.lang.String arg) java.lang.Class> 13 dup 14 putstatic #14 <Field X#class$0 java.lang.Class> 17 goto 32 20 new #23 java.lang.NoClassDefFoundError 23 dup_x1 24 swap 25 invokevirtual #29 <Method java.lang.Throwable#getMessage() java.lang.String> 28 invokespecial #33 <Constructor java.lang.NoClassDefFoundError (java.lang.String arg)> 31 athrow 32 invokevirtual #37 <Method java.lang.Class#desiredAssertionStatus() boolean> 35 ifne 42 38 iconst_1 39 goto 43 42 iconst_0 43 putstatic #39 <Field X#$assertionsDisabled boolean> 46 return Exception Table: [pc: 8, pc: 13] -> 20 when : java.lang.ClassNotFoundException Line number attribute: [pc: 0, line: 1] /* Method descriptor #11 ()V */ public X(); /* Stack: 1, Locals: 1 */ Code attribute: 0 aload_0 1 invokespecial #44 <Constructor java.lang.Object()> 4 return Line number attribute: [pc: 0, line: 1] /* Method descriptor #46 ([Ljava/lang/String;)V */ public static void main(String[] arg); /* Stack: 3, Locals: 1 */ Code attribute: 0 getstatic #39 <Field X#$assertionsDisabled boolean> 3 ifne 19 6 goto 19 9 new #48 java.lang.AssertionError 12 dup 13 iload 255 15 invokespecial #51 <Constructor java.lang.AssertionError(int arg)> 18 athrow 19 getstatic #57 <Field java.lang.System#out java.io.PrintStream> 22 ldc #59 <String "SUCCESS"> 24 invokevirtual #64 <Method java.io.PrintStream#println (java.lang.String arg) void> 27 return Line number attribute: [pc: 0, line: 4] [pc: 19, line: 5] [pc: 27, line: 6] }
Offending line is: 13 iload 255
In fact the whole block: 9 new #48 java.lang.AssertionError 12 dup 13 iload 255 15 invokespecial #51 <Constructor java.lang.AssertionError(int arg)> 18 athrow is unreachable. If the condition of the assert statement is inlined to true we don't need to generate the assertion error because it cannot happen.
Indeed. Fixed by optimizing out the entire chunk when condition is inlined to true.
Fixed.
Fixed
Verified.