Bug 26138 - JACKS - The null literal should not be considered as a constant expression
Summary: JACKS - The null literal should not be considered as a constant expression
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.1   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: 2.1 M4   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-11-13 13:23 EST by Olivier Thomann CLA
Modified: 2002-12-19 05:16 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.