JDK-8226877 : String.intern() does not give expected result.
  • Type: Bug
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 11,12
  • Priority: P2
  • Status: Closed
  • Resolution: Not an Issue
  • OS: windows_10
  • CPU: x86_64
  • Submitted: 2019-06-26
  • Updated: 2019-10-02
  • Resolved: 2019-06-27
Description
ADDITIONAL SYSTEM INFORMATION :
windows 10

A DESCRIPTION OF THE PROBLEM :
When I use String a = new String("1") + new String("2");  then String b = "12";   when I compare a and b, I find that the output is false, then I try to put the above The splicing string changes the value, and the other changes are no problem. They are all true. Only when "12" returns false here, and when I change the version back to java8, there is no such problem.

REGRESSION : Last worked in version 8u202

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
public static void main(String[] args) {
		String a = new String("1") + new String("2");
		a.intern();
		a.intern();
		String b = "12";
		System.out.println(a == b);

	}

ACTUAL -
false

---------- BEGIN SOURCE ----------
public static void main(String[] args) {
		String a = new String("1") + new String("2");
		a.intern();
		a.intern();
		String b = "12";
		System.out.println(a == b);

	}
---------- END SOURCE ----------

FREQUENCY : always



Comments
In the provided code, the result of a.intern() is discarded. If you change the line to `a = a.intern()`, then the results will be consistent across all JDK versions.
27-06-2019

To reproduce the issue, run the attached test case. JDK 8u212 - Pass JDK 11.0.2 - Pass JDK 11.0.3-oracle - Fail JDK 12- Fail JDK 12.0.1 - Fail JDK 13-ea+22 -Pass Output is "false" in all the failed cases.
27-06-2019