sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1409101 - /sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/type/AbstractInternationalString.java
Date Wed, 14 Nov 2012 06:57:18 GMT
Author: desruisseaux
Date: Wed Nov 14 06:57:17 2012
New Revision: 1409101

URL: http://svn.apache.org/viewvc?rev=1409101&view=rev
Log:
Slighly more robust AbstractInternationalString in case of non-synchronized access from many
threads.
This is not completly safe (we would need to declare the field volatile for that), but is
okay if the
creation of the default string is itself synchronized, and that concurrent creation of that
default
string creates equals (not necessarily same) instances.

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

Modified: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/type/AbstractInternationalString.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/type/AbstractInternationalString.java?rev=1409101&r1=1409100&r2=1409101&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/type/AbstractInternationalString.java
(original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/type/AbstractInternationalString.java
Wed Nov 14 06:57:17 2012
@@ -67,13 +67,15 @@ public abstract class AbstractInternatio
      */
     @Override
     public int length() {
-        if (defaultValue == null) {
-            defaultValue = toString();
-            if (defaultValue == null) {
+        String text = defaultValue;
+        if (text == null) {
+            text = toString();
+            if (text == null) {
                 return 0;
             }
+            defaultValue = text;
         }
-        return defaultValue.length();
+        return text.length();
     }
 
     /**
@@ -86,13 +88,15 @@ public abstract class AbstractInternatio
      */
     @Override
     public char charAt(final int index) throws IndexOutOfBoundsException {
-        if (defaultValue == null) {
-            defaultValue = toString();
-            if (defaultValue == null) {
+        String text = defaultValue;
+        if (text == null) {
+            text = toString();
+            if (text == null) {
                 throw new StringIndexOutOfBoundsException();
             }
+            defaultValue = text;
         }
-        return defaultValue.charAt(index);
+        return text.charAt(index);
     }
 
     /**
@@ -107,16 +111,18 @@ public abstract class AbstractInternatio
      */
     @Override
     public CharSequence subSequence(final int start, final int end) {
-        if (defaultValue == null) {
-            defaultValue = toString();
-            if (defaultValue == null) {
+        String text = defaultValue;
+        if (text == null) {
+            text = toString();
+            if (text == null) {
                 if (start == 0 && end == 0) {
                     return "";
                 }
                 throw new StringIndexOutOfBoundsException();
             }
+            defaultValue = text;
         }
-        return defaultValue.substring(start, end);
+        return text.substring(start, end);
     }
 
     /**
@@ -142,13 +148,15 @@ public abstract class AbstractInternatio
      */
     @Override
     public String toString() {
-        if (defaultValue == null) {
-            defaultValue = toString(Locale.getDefault());
-            if (defaultValue == null) {
+        String text = defaultValue;
+        if (text == null) {
+            text = toString(Locale.getDefault());
+            if (text == null) {
                 return "";
             }
+            defaultValue = text;
         }
-        return defaultValue;
+        return text;
     }
 
     /**



Mime
View raw message