Bug 26138

Summary: JACKS - The null literal should not be considered as a constant expression
Product: [Eclipse Project] JDT Reporter: Olivier Thomann <Olivier_Thomann>
Component: CoreAssignee: Philipe Mulet <philippe_mulet>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3    
Version: 2.1   
Target Milestone: 2.1 M4   
Hardware: PC   
OS: Windows 2000   
Whiteboard:

Description Olivier Thomann CLA 2002-11-13 13:23:52 EST
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.
Comment 1 Olivier Thomann CLA 2002-11-13 13:34:10 EST
Another test case:
class A {
	void foo() {
		boolean b = "" + null == "null";
		System.out.println(b);
	}
}
Comment 2 Philipe Mulet CLA 2002-11-14 08:38:14 EST
The first example seems right to me. We are more optimized.
Do you have an example showing an actual problem ?
Comment 3 Olivier Thomann CLA 2002-11-14 08:41:11 EST
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.
Comment 4 Philipe Mulet CLA 2002-11-18 12:28:58 EST
Took String concatenation inlining when null is an argument.
Keeping internal constant folding with null literals still.

Comment 5 Philipe Mulet CLA 2002-11-18 12:29:15 EST
Fixed
Comment 6 Philipe Mulet CLA 2002-11-19 09:16:44 EST
Removed internal null constants.
Fixed
Comment 7 David Audel CLA 2002-12-19 05:16:59 EST
Verified.