You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by ar...@apache.org on 2006/06/12 03:34:40 UTC

svn commit: r413558 - /incubator/harmony/enhanced/classlibadapter/trunk/modules/kernel/src/main/java/java/lang/String.java

Author: archie
Date: Sun Jun 11 18:34:40 2006
New Revision: 413558

URL: http://svn.apache.org/viewvc?rev=413558&view=rev
Log:
Fix bug in r413349: the values in the WeakHashMap need to be weak too.

Modified:
    incubator/harmony/enhanced/classlibadapter/trunk/modules/kernel/src/main/java/java/lang/String.java

Modified: incubator/harmony/enhanced/classlibadapter/trunk/modules/kernel/src/main/java/java/lang/String.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlibadapter/trunk/modules/kernel/src/main/java/java/lang/String.java?rev=413558&r1=413557&r2=413558&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlibadapter/trunk/modules/kernel/src/main/java/java/lang/String.java (original)
+++ incubator/harmony/enhanced/classlibadapter/trunk/modules/kernel/src/main/java/java/lang/String.java Sun Jun 11 18:34:40 2006
@@ -74,13 +74,14 @@
 
 import java.io.Serializable;
 import java.io.UnsupportedEncodingException;
+import java.lang.ref.WeakReference;
 import java.nio.ByteBuffer;
 import java.nio.CharBuffer;
 import java.nio.charset.Charset;
 import java.util.Comparator;
 import java.util.Locale;
-import java.util.regex.Pattern;
 import java.util.WeakHashMap;
+import java.util.regex.Pattern;
 
 /**
  * @com.intel.drl.spec_ref 
@@ -1331,12 +1332,14 @@
 
     public String intern() {
         synchronized (internedStrings) {
-            String i = (String)internedStrings.get(this);
-            if (i == null) {
-		internedStrings.put(this, this);
-                i = this;
+            WeakReference ref = (WeakReference)internedStrings.get(this);
+            if (ref != null) {
+		String s = (String)ref.get();	// this could return null
+		if (s != null)
+		    return s;
             }
-            return i;
+	    internedStrings.put(this, new WeakReference(this));
+	    return this;
         }
     }
 }