Bug 9169

Summary: Wrong code generation for comparison of string constants
Product: [Eclipse Project] JDT Reporter: Olivier Thomann <Olivier_Thomann>
Component: CoreAssignee: Philipe Mulet <philippe_mulet>
Status: VERIFIED FIXED QA Contact:
Severity: critical    
Priority: P1    
Version: 2.0   
Target Milestone: 2.0 M3   
Hardware: Other   
OS: All   
Whiteboard:

Description Olivier Thomann CLA 2002-02-06 10:30:05 EST
Take the following test case:
[public class Test {
	public static final String STRCONST1 = 
"1";
	public static final String STRCONST2 = "2";
	public static final String MYSTRCONST = 
STRCONST2;

	public static void main(String[] args) {
		if (MYSTRCONST == STRCONST1) 
{
			System.out.println("STRCONST1");
		} else if (MYSTRCONST == STRCONST2) 
{
			System.out.println("STRCONST2");
		} else 
{
			System.out.println("OTHER");
		}
	}
}]

Compiler it with javac 1.3.1 and run 
it:
You get:
STRCONST2

With Eclipse 20020125, you get:
STRCONST1

The right value 
is STRCONST2.
Comment 1 Olivier Thomann CLA 2002-02-06 10:38:07 EST
The bug is really simple. It comes from the:
public boolean compileTimeEqual(StringConstant 
right){...} method on StringConstant. This method always returns true. But it should 
do:
public boolean compileTimeEqual(StringConstant right){
	//String are intermed in 
the compiler==>thus if two string constant
	//get to be compared, it is an equal on the vale 
which is done
	if (this.value == null) {
		return right.value == null;
	}
	return 
this.value.equals(right.value);
}

If I changed that, the test case is compiled and 
executed without a problem.
Comment 2 Olivier Thomann CLA 2002-02-06 12:30:50 EST
Fix released in HEAD and regression test added.
Comment 3 Philipe Mulet CLA 2002-02-07 13:13:48 EST
Backported to 1.0 stream (rollup2)
Comment 4 Olivier Thomann CLA 2002-02-07 16:16:51 EST
Verified and added test case (see ConformTest.test108).
Comment 5 Olivier Thomann CLA 2002-02-13 13:37:19 EST
Verified with official rollup2.