Community
Participate
Working Groups
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.
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.
Fix released in HEAD and regression test added.
Backported to 1.0 stream (rollup2)
Verified and added test case (see ConformTest.test108).
Verified with official rollup2.