This is an automated email from the ASF dual-hosted git repository.

desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git


The following commit(s) were added to refs/heads/geoapi-4.0 by this push:
     new ece63c46f5 Fix a never-ending loop when temporal objects are compared 
as `java.lang.Object`. Add a note about future development needed in WKT 
parsing. Minor cleaning.
ece63c46f5 is described below

commit ece63c46f5e28bc50b6c5d0c995e218bad71871e
Author: Martin Desruisseaux <martin.desruisse...@geomatys.com>
AuthorDate: Tue Apr 1 17:27:15 2025 +0200

    Fix a never-ending loop when temporal objects are compared as 
`java.lang.Object`.
    Add a note about future development needed in WKT parsing.
    Minor cleaning.
---
 .../main/org/apache/sis/image/ImageProcessor.java   |  4 ++--
 .../main/org/apache/sis/temporal/TimeMethods.java   |  6 +++++-
 .../org/apache/sis/io/wkt/GeodeticObjectParser.java | 21 ++++++++++++---------
 .../org/apache/sis/util/collection/WeakHashSet.java |  1 +
 4 files changed, 20 insertions(+), 12 deletions(-)

diff --git 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/ImageProcessor.java
 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/ImageProcessor.java
index 9cdae190a2..92d59fa7a4 100644
--- 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/ImageProcessor.java
+++ 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/ImageProcessor.java
@@ -477,7 +477,7 @@ public class ImageProcessor implements Cloneable {
      */
     public synchronized void setPositionalAccuracyHints(final Quantity<?>... 
hints) {
         if (hints != null) {
-            final Quantity<?>[] copy = new Quantity<?>[hints.length];
+            final var copy = new Quantity<?>[hints.length];
             int n = 0;
             for (final Quantity<?> hint : hints) {
                 if (hint != null) copy[n++] = hint;
@@ -1551,7 +1551,7 @@ public class ImageProcessor implements Cloneable {
     @SuppressWarnings("LocalVariableHidesMemberVariable")
     public boolean equals(final Object object) {
         if (object != null && object.getClass() == getClass()) {
-            final ImageProcessor other = (ImageProcessor) object;
+            final var other = (ImageProcessor) object;
             final Mode          executionMode;
             final ErrorHandler  errorHandler;
             final Interpolation interpolation;
diff --git 
a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/temporal/TimeMethods.java
 
b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/temporal/TimeMethods.java
index f6b71c4910..da063eeb9e 100644
--- 
a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/temporal/TimeMethods.java
+++ 
b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/temporal/TimeMethods.java
@@ -197,7 +197,11 @@ public class TimeMethods<T> implements Serializable {
          * only as parameter type (no collection), it is okay to use it that 
way.
          */
         final TimeMethods<? super T> tc = findSpecialized(type);
-        if (tc != null) {
+        /*
+         * The implementation of `TimeMethods.before/equals/after` methods 
delegate to this method in the
+         * most generic case. In such cases, this block must be excluded for 
avoiding a never-ending loop.
+         */
+        if (tc != null && !tc.isDynamic()) {
             /*
              * Found one of the special cases listed in `INTERFACES` or 
`FINAL_TYPE`.
              * If the other type is compatible, the comparison is executed 
directly.
diff --git 
a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/io/wkt/GeodeticObjectParser.java
 
b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/io/wkt/GeodeticObjectParser.java
index 57e02e04a0..9da2a6ded1 100644
--- 
a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/io/wkt/GeodeticObjectParser.java
+++ 
b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/io/wkt/GeodeticObjectParser.java
@@ -18,7 +18,6 @@ package org.apache.sis.io.wkt;
 
 import java.net.URI;
 import java.util.Map;
-import java.util.List;
 import java.util.Locale;
 import java.util.HashMap;
 import java.util.IdentityHashMap;
@@ -741,7 +740,7 @@ class GeodeticObjectParser extends MathTransformParser 
implements Comparator<Coo
         CoordinateSystemAxis[] axes = null;
         CoordinateSystemAxis axis = parseAxis(type == null ? MANDATORY : 
OPTIONAL, parent, type, defaultUnit);
         if (axis != null) {
-            final List<CoordinateSystemAxis> list = new ArrayList<>(dimension 
+ 2);
+            final var list = new ArrayList<CoordinateSystemAxis>(dimension + 
2);
             do {
                 list.add(axis);
                 axis = parseAxis(list.size() < dimension ? MANDATORY : 
OPTIONAL, parent, type, defaultUnit);
@@ -890,7 +889,7 @@ class GeodeticObjectParser extends MathTransformParser 
implements Comparator<Coo
          */
         final String name;
         {   // For keeping the `buffer` variable local to this block.
-            final StringBuilder buffer = new StringBuilder();
+            final var buffer = new StringBuilder();
             if (type != null && !type.isEmpty()) {
                 final int c = type.codePointAt(0);
                 buffer.appendCodePoint(Character.toUpperCase(c))
@@ -1187,7 +1186,7 @@ class GeodeticObjectParser extends MathTransformParser 
implements Comparator<Coo
         if (element == null) {
             return null;
         }
-        final double[] values = new double[ToWGS84.length];
+        final var values = new double[ToWGS84.length];
         for (int i=0; i<values.length;) {
             values[i] = element.pullDouble(ToWGS84[i]);
             if ((++i % 3) == 0 && element.isEmpty()) {
@@ -1195,7 +1194,7 @@ class GeodeticObjectParser extends MathTransformParser 
implements Comparator<Coo
             }
         }
         element.close(ignoredElements);
-        final BursaWolfParameters info = new 
BursaWolfParameters(CommonCRS.WGS84.datum(), null);
+        final var info = new BursaWolfParameters(CommonCRS.WGS84.datum(), 
null);
         info.setValues(values);
         return info;
     }
@@ -2156,6 +2155,10 @@ class GeodeticObjectParser extends MathTransformParser 
implements Comparator<Coo
             cs = parseCoordinateSystem(element, WKTKeywords.Cartesian, 2, 
isWKT1, csUnit, geoCRS.getDatum());
             final Map<String,?> properties = parseMetadataAndClose(element, 
name, conversion);
             if (cs instanceof CartesianCS) {
+                /*
+                 * TODO: if the CartesianCS is three-dimensional, we need to 
ensure that the base CRS is also
+                 * three-dimensional. We could do that by parsing the CS 
before to invoke `parseGeodeticCRS`.
+                 */
                 final CRSFactory crsFactory = factories.getCRSFactory();
                 return crsFactory.createProjectedCRS(properties, (GeodeticCRS) 
geoCRS, conversion, (CartesianCS) cs);
             }
@@ -2190,7 +2193,7 @@ class GeodeticObjectParser extends MathTransformParser 
implements Comparator<Coo
         }
         final String  name = element.pullString("name");
         CoordinateReferenceSystem crs;
-        final List<CoordinateReferenceSystem> components = new ArrayList<>(4);
+        final var components = new ArrayList<CoordinateReferenceSystem>(4);
         while ((crs = parseCoordinateReferenceSystem(element, 
components.size() < 2)) != null) {
             components.add(crs);
         }
@@ -2234,8 +2237,8 @@ class GeodeticObjectParser extends MathTransformParser 
implements Comparator<Coo
          * We have to guess some reasonable one with arbitrary units. We try 
to construct the one which
          * contains as few information as possible, in order to avoid 
providing wrong information.
          */
-        final CoordinateSystemAxis[] axes = new 
CoordinateSystemAxis[toBase.getSourceDimensions()];
-        final StringBuilder buffer = new StringBuilder(name).append(" axis ");
+        final var axes = new 
CoordinateSystemAxis[toBase.getSourceDimensions()];
+        final var buffer = new StringBuilder(name).append(" axis ");
         final int start = buffer.length();
         final CSFactory csFactory = factories.getCSFactory();
         try {
@@ -2249,7 +2252,7 @@ class GeodeticObjectParser extends MathTransformParser 
implements Comparator<Coo
             }
             final Map<String,Object> properties = 
parseMetadataAndClose(element, name, baseCRS);
             final Map<String,Object> axisName = 
singletonMap(CoordinateSystem.NAME_KEY, AxisDirections.appendTo(new 
StringBuilder("CS"), axes));
-            final CoordinateSystem derivedCS = new AbstractCS(axisName, axes);
+            final var derivedCS = new AbstractCS(axisName, axes);
             /*
              * Creates a derived CRS from the information found in a WKT 1 
{@code FITTED_CS} element.
              * This coordinate system cannot be easily constructed from the 
information provided by
diff --git 
a/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/collection/WeakHashSet.java
 
b/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/collection/WeakHashSet.java
index ef7c7ba71c..1407176957 100644
--- 
a/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/collection/WeakHashSet.java
+++ 
b/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/collection/WeakHashSet.java
@@ -285,6 +285,7 @@ public class WeakHashSet<E> extends AbstractSet<E> 
implements CheckedContainer<E
      *         }
      *         // Do the comparison
      *     }
+     *     }
      *
      * @param  <T>      the type of the element to get.
      * @param  element  the element to get or to add in the set if not already 
presents. Can be {@code null}.

Reply via email to