-
Bug
-
Resolution: Fixed
-
P2
-
18.0.2.1, 19
-
b16
-
generic
-
generic
-
Verified
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8294268 | 19.0.2 | Jan Lahoda | P2 | Closed | Fixed | b02 |
JDK-8293992 | 17.0.6-oracle | Jan Lahoda | P2 | Closed | Fixed | b01 |
JDK-8294732 | 17.0.6 | Victor Rudometov | P2 | Resolved | Fixed | b01 |
JDK-8293990 | 11.0.18-oracle | Jan Lahoda | P2 | Closed | Fixed | b01 |
JDK-8294733 | 11.0.18 | Victor Rudometov | P2 | Resolved | Fixed | b01 |
Given the test code provided, we would expect that
- the call on line 20 ("".equals(newString)) evaluates to "false"
- the call on line 21 ("A string".equals(newString)) evaluates to "true"
Running the code, however, shows that
- the call on line 20 evaluates to "true"
- the call on line 21 evaluates to "false".
It is noteworthy that the calls on line 34 and 35 evaluate to the expected values. The only difference between this two methods is that in broken(), the variable input is final, where in ok(), it is not.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile and run the test code.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The call on line 20 ("".equals(newString)) should evaluates to "false".
The call on line 21 ("A string".equals(newString)) should evaluates to "true".
ACTUAL -
The call on line 20 ("".equals(newString)) evaluates to "true".
The call on line 21 ("A string".equals(newString)) evaluates to "false".
---------- BEGIN SOURCE ----------
import java.lang.reflect.InvocationTargetException;
class Scratch {
public static void main(String... args)
throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
broken();
ok();
}
private static void broken()
throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
final var input = "A string";
final var theClass = input.getClass();
final var constructor = theClass.getConstructor();
final var newString = constructor.newInstance();
System.out.printf(
("in broken(), \"\".equals(newString) = %b\n" +
"in broken(), \"A string\".equals(newString) = %b\n"),
"".equals(newString), // line 20
"A string".equals(newString)); // line 21
}
private static void ok()
throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
var input = "A string";
final var theClass = input.getClass();
final var constructor = theClass.getConstructor();
final var newString = constructor.newInstance();
System.out.printf(
("in ok(), \"\".equals(newString) = %b\n" +
"in ok(), \"A string\".equals(newString) = %b\n"),
"".equals(newString), // line 34
"A string".equals(newString)); // line 35
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
not define variable "input" as "final".
FREQUENCY : always
- backported by
-
JDK-8294732 Duplicate ldc generated by javac
- Resolved
-
JDK-8294733 Duplicate ldc generated by javac
- Resolved
-
JDK-8293990 Duplicate ldc generated by javac
- Closed
-
JDK-8293992 Duplicate ldc generated by javac
- Closed
-
JDK-8294268 Duplicate ldc generated by javac
- Closed
- links to
-
Commit openjdk/jdk11u-dev/ca33f6c5
-
Commit openjdk/jdk17u-dev/3bcdb666
-
Commit openjdk/jdk19u/b5f79886
-
Commit openjdk/jdk/39cd1635
-
Review openjdk/jdk11u-dev/1381
-
Review openjdk/jdk17u-dev/758
-
Review openjdk/jdk19u/25
-
Review openjdk/jdk/10272