sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1451034 - /sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/iso/AbstractInternationalString.java
Date Wed, 27 Feb 2013 23:35:12 GMT
Author: desruisseaux
Date: Wed Feb 27 23:35:12 2013
New Revision: 1451034

URL: http://svn.apache.org/r1451034
Log:
Fixed a synchronization hole.

Modified:
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/iso/AbstractInternationalString.java

Modified: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/iso/AbstractInternationalString.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/iso/AbstractInternationalString.java?rev=1451034&r1=1451033&r2=1451034&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/iso/AbstractInternationalString.java
[UTF-8] (original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/iso/AbstractInternationalString.java
[UTF-8] Wed Feb 27 23:35:12 2013
@@ -22,6 +22,7 @@ import java.util.Formattable;
 import java.util.FormattableFlags;
 import org.opengis.util.InternationalString;
 import org.apache.sis.internal.util.Utilities;
+import org.apache.sis.util.CharSequences;
 
 
 /**
@@ -45,11 +46,15 @@ public abstract class AbstractInternatio
      * if this string has not yet been determined. This is the default string returned by
      * {@link #toString()} and others methods from the {@link CharSequence} interface.
      *
-     * <p>This field is not serialized because serialization is often used for data
transmission
-     * between a server and a client, and the client may not use the same locale than the
server.
-     * We want the locale to be examined again on the client side.</p>
+     * {@section Thread safety}
+     * For thread safety this field shall either be read and written in a synchronized block,
+     * or be fixed at construction time and never changed after than point. All other usages
+     * are prohibited.
      *
-     * This field is read and written by {@link SimpleInternationalString}.
+     * {@section Serialization}
+     * This field is not serialized because serialization is often used for data transmission
+     * between a server and a client, and the client may not use the same locale than the
server.
+     * We want the locale to be examined again on the client side.
      */
     transient String defaultValue;
 
@@ -67,15 +72,7 @@ public abstract class AbstractInternatio
      */
     @Override
     public int length() {
-        String text = defaultValue;
-        if (text == null) {
-            text = toString();
-            if (text == null) {
-                return 0;
-            }
-            defaultValue = text;
-        }
-        return text.length();
+        return CharSequences.length(toString());
     }
 
     /**
@@ -88,15 +85,7 @@ public abstract class AbstractInternatio
      */
     @Override
     public char charAt(final int index) throws IndexOutOfBoundsException {
-        String text = defaultValue;
-        if (text == null) {
-            text = toString();
-            if (text == null) {
-                throw new StringIndexOutOfBoundsException();
-            }
-            defaultValue = text;
-        }
-        return text.charAt(index);
+        return toString().charAt(index);
     }
 
     /**
@@ -111,16 +100,12 @@ public abstract class AbstractInternatio
      */
     @Override
     public CharSequence subSequence(final int start, final int end) {
-        String text = defaultValue;
+        final String text = toString();
         if (text == null) {
-            text = toString();
-            if (text == null) {
-                if (start == 0 && end == 0) {
-                    return "";
-                }
-                throw new StringIndexOutOfBoundsException();
+            if (start == 0 && end == 0) {
+                return "";
             }
-            defaultValue = text;
+            throw new StringIndexOutOfBoundsException();
         }
         return text.substring(start, end);
     }
@@ -165,7 +150,7 @@ public abstract class AbstractInternatio
      * @return The string in the default locale.
      */
     @Override
-    public String toString() {
+    public synchronized String toString() {
         String text = defaultValue;
         if (text == null) {
             text = toString(Locale.getDefault());



Mime
View raw message