Author: desruisseaux
Date: Tue Mar 27 13:59:17 2018
New Revision: 1827839

URL: http://svn.apache.org/viewvc?rev=1827839&view=rev
Log:
Fix some test failures when executed with JDK9.
Patch by Alexis Manin: https://issues.apache.org/jira/browse/SIS-392

Modified:
    
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/converter/ObjectToString.java
    
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/converter/SystemConverter.java
    
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/converter/package-info.java
    
sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/util/collection/IntegerListTest.java

Modified: 
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/converter/ObjectToString.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/converter/ObjectToString.java?rev=1827839&r1=1827838&r2=1827839&view=diff
==============================================================================
--- 
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/converter/ObjectToString.java
 [UTF-8] (original)
+++ 
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/converter/ObjectToString.java
 [UTF-8] Tue Mar 27 13:59:17 2018
@@ -38,7 +38,7 @@ import org.apache.sis.math.FunctionPrope
  * This base class and all inner classes are immutable, and thus inherently 
thread-safe.
  *
  * @author  Martin Desruisseaux (Geomatys)
- * @version 0.3
+ * @version 1.0
  *
  * @param <S>  the source type.
  *
@@ -91,11 +91,20 @@ class ObjectToString<S> extends SystemCo
 
     /**
      * Returns the singleton instance on deserialization, if any.
+     *
+     * @see StringConverter#unique()
      */
     @Override
     public final ObjectConverter<S, String> unique() {
+        /*
+         * The checks against null references are needed because on 
deserialization,
+         * the inverse of this inverse converter may not be assigned a value 
yet.
+         */
         if (inverse != null) {
-            return inverse.unique().inverse();              // Will typically 
delegate to StringConverter.
+            ObjectConverter<S, String> singleton = inverse.unique().inverse(); 
     // Will typically delegate to StringConverter.
+            if (singleton != null) {
+                return singleton;
+            }
         }
         return this;
     }

Modified: 
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/converter/SystemConverter.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/converter/SystemConverter.java?rev=1827839&r1=1827838&r2=1827839&view=diff
==============================================================================
--- 
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/converter/SystemConverter.java
 [UTF-8] (original)
+++ 
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/converter/SystemConverter.java
 [UTF-8] Tue Mar 27 13:59:17 2018
@@ -33,7 +33,7 @@ import org.apache.sis.util.resources.Err
  * and thread-safe too if they are intended to be cached in {@link 
ConverterRegistry}.
  *
  * @author  Martin Desruisseaux (Geomatys)
- * @version 0.3
+ * @version 1.0
  *
  * @param <S>  the base type of source objects.
  * @param <T>  the base type of converted objects.
@@ -141,10 +141,23 @@ abstract class SystemConverter<S,T> exte
      * Otherwise this converter is returned <strong>without</strong> being 
cached.
      *
      * @return the unique instance, or {@code this} if no unique instance can 
be found.
+     *
+     * @see ObjectToString#unique()
      */
     public ObjectConverter<S,T> unique() {
-        final ObjectConverter<S,T> existing = 
SystemRegistry.INSTANCE.findEquals(this);
-        return (existing != null) ? existing : this;
+        /*
+         * On deserialization, some fields are not yet assigned a value at the 
moment of this call.
+         * This happen when this unique() method is invoked by 
inverse().readResolve() — not by the
+         * readResolve() method of this class — in which case the 
deserialization process is not yet
+         * fully completed. In such cases, we can not determine if an existing 
instance is available.
+         * We return the current instance as a fallback, leaving to 
inverse().readResolve() the task
+         * of returning a unique instance after it finished its own 
deserialization process.
+         */
+        if (sourceClass != null && targetClass != null) {
+            final ObjectConverter<S,T> existing = 
SystemRegistry.INSTANCE.findEquals(this);
+            if (existing != null) return existing;
+        }
+        return this;
     }
 
     /**

Modified: 
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/converter/package-info.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/converter/package-info.java?rev=1827839&r1=1827838&r2=1827839&view=diff
==============================================================================
--- 
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/converter/package-info.java
 [UTF-8] (original)
+++ 
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/converter/package-info.java
 [UTF-8] Tue Mar 27 13:59:17 2018
@@ -42,7 +42,7 @@
  * classpath changes.</p>
  *
  * @author  Martin Desruisseaux (Geomatys)
- * @version 0.8
+ * @version 1.0
  * @since   0.3
  * @module
  */

Modified: 
sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/util/collection/IntegerListTest.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/util/collection/IntegerListTest.java?rev=1827839&r1=1827838&r2=1827839&view=diff
==============================================================================
--- 
sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/util/collection/IntegerListTest.java
 [UTF-8] (original)
+++ 
sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/util/collection/IntegerListTest.java
 [UTF-8] Tue Mar 27 13:59:17 2018
@@ -40,7 +40,7 @@ import static org.apache.sis.test.Assert
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @author  Alexis Manin (Geomatys)
- * @version 0.8
+ * @version 1.0
  * @since   0.7
  * @module
  */
@@ -291,6 +291,6 @@ public final strictfp class IntegerListT
         final Random random = TestUtilities.createRandomNumberGenerator();
         return IntStream.generate(() -> random.nextInt(maxValue))
                 .limit(size)
-                .collect(() -> new IntegerList(size, maxValue), 
IntegerList::addInt, null);
+                .collect(() -> new IntegerList(size, maxValue), 
IntegerList::addInt, (l1, l2) -> l1.addAll(l2));
     }
 }


Reply via email to