Bug 9169 - Wrong code generation for comparison of string constants
Summary: Wrong code generation for comparison of string constants
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.0   Edit
Hardware: Other All
: P1 critical (vote)
Target Milestone: 2.0 M3   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-02-06 10:30 EST by Olivier Thomann CLA
Modified: 2002-02-13 13:37 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-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.