Community
Participate
Working Groups
Using 1112, we inline null == null. class A { void foo() { boolean b = null == null; System.out.println(b); } } Code attribute: /* Stack: 2, Locals: 2 */ 0 iconst_1 1 istore_1 2 getstatic #20 <Field java.lang.System#out java.io.PrintStream> 5 iload_1 6 invokevirtual #26 <Method java.io.PrintStream#println(boolean arg) void> 9 return We should have instead: Method void foo() 0 aconst_null 1 ifnonnull 8 4 iconst_1 5 goto 9 8 iconst_0 9 istore_1 10 getstatic #2 <Field java.io.PrintStream out> 13 iload_1 14 invokevirtual #3 <Method void println(boolean)> 17 return Javac 1.4 and jikes generate the right bytecode sequence.
Another test case: class A { void foo() { boolean b = "" + null == "null"; System.out.println(b); } }
The first example seems right to me. We are more optimized. Do you have an example showing an actual problem ?
In the second example we don't do the string concatenation. We inline the constant. In fact we should never inline the constant when it is a null literal. I am not sure we "can" optimize the first case.
Took String concatenation inlining when null is an argument. Keeping internal constant folding with null literals still.
Fixed
Removed internal null constants. Fixed
Verified.