...
When the intern method is invoked, if the pool already contains a string equal to this String object as determined by the equals(Object) method, then the string from the pool is returned. Otherwise, this String object is added to the pool and a reference to this String object is returned.
Thus As a result a String
constant behaves like a global variable in the JVM. As demonstrated in this noncompliant example, even if each instance of an object maintains its own field lock
, it points to a common String
constant in the JVM. Legitimate code that locks on the same String constant will render all synchronization attempts inadequate. Likewise, hostile code from any other package can deliberately exploit this vulnerability.
...