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

commit 0b087ad5c81a27cd891546d891eab9754194d405
Author: Martin Desruisseaux <martin.desruisse...@geomatys.com>
AuthorDate: Sat Dec 17 10:39:36 2022 +0100

    Fix an ArrayStoreException when parsing a WKT with an invalid operation 
method.
    
    https://lists.apache.org/thread/g206zssnxltdc88x2ovjg6zpdmtyb8qc
---
 .../java/org/apache/sis/referencing/CRSTest.java    | 21 ++++++++++++++++++++-
 .../DefaultCoordinateOperationFactoryTest.java      | 19 ++++++++++++++++++-
 .../sis/util/resources/IndexedResourceBundle.java   |  3 ++-
 3 files changed, 40 insertions(+), 3 deletions(-)

diff --git 
a/core/sis-referencing/src/test/java/org/apache/sis/referencing/CRSTest.java 
b/core/sis-referencing/src/test/java/org/apache/sis/referencing/CRSTest.java
index 9e01a2c727..0ddcfc19c4 100644
--- a/core/sis-referencing/src/test/java/org/apache/sis/referencing/CRSTest.java
+++ b/core/sis-referencing/src/test/java/org/apache/sis/referencing/CRSTest.java
@@ -20,8 +20,8 @@ import java.util.Map;
 import java.util.HashMap;
 import java.util.Arrays;
 import java.util.List;
-import org.apache.sis.internal.system.Loggers;
 import org.opengis.util.FactoryException;
+import org.opengis.util.NoSuchIdentifierException;
 import org.opengis.referencing.NoSuchAuthorityCodeException;
 import org.opengis.referencing.crs.CoordinateReferenceSystem;
 import org.opengis.referencing.crs.GeographicCRS;
@@ -33,6 +33,7 @@ import org.apache.sis.referencing.crs.DefaultGeographicCRS;
 import org.apache.sis.referencing.crs.DefaultProjectedCRS;
 import org.apache.sis.metadata.iso.extent.DefaultGeographicBoundingBox;
 import org.apache.sis.metadata.iso.extent.DefaultExtent;
+import org.apache.sis.internal.system.Loggers;
 import org.apache.sis.util.ComparisonMode;
 import org.apache.sis.util.Utilities;
 
@@ -218,6 +219,24 @@ public final strictfp class CRSTest extends TestCase {
         assertEquals("GCS WGS 1984", crs.getName().getCode());
     }
 
+    /**
+     * Verifies that parsing a WKT with an unknown operation method throws 
{@link NoSuchIdentifierException}.
+     *
+     * @throws FactoryException if an unexpected error occurred.
+     */
+    @Test
+    public void testFromInvalidWKT() throws FactoryException {
+        try {
+            CRS.fromWKT("PROJCS[\"Foo\", GEOGCS[\"Foo\", DATUM[\"Foo\", 
SPHEROID[\"Sphere\", 6371000, 0]], " +
+                        "UNIT[\"Degree\", 0.0174532925199433]], PROJECTION[\"I 
do not exist\"], " +
+                        "UNIT[\"MEtre\", 1]]");
+            fail("Expected NoSuchIdentifierException");
+        } catch (NoSuchIdentifierException e) {
+            final String message = e.getMessage();
+            assertTrue(message, message.contains("I do not exist"));
+        }
+    }
+
     /**
      * Tests {@link CRS#suggestCommonTarget(GeographicBoundingBox, 
CoordinateReferenceSystem...)}.
      *
diff --git 
a/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/DefaultCoordinateOperationFactoryTest.java
 
b/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/DefaultCoordinateOperationFactoryTest.java
index 840b6e2e87..6b1a6b19af 100644
--- 
a/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/DefaultCoordinateOperationFactoryTest.java
+++ 
b/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/DefaultCoordinateOperationFactoryTest.java
@@ -19,6 +19,7 @@ package org.apache.sis.referencing.operation;
 import java.util.List;
 import java.text.ParseException;
 import org.opengis.util.FactoryException;
+import org.opengis.util.NoSuchIdentifierException;
 import org.opengis.parameter.ParameterValueGroup;
 import org.opengis.referencing.crs.CoordinateReferenceSystem;
 import org.opengis.referencing.operation.ConcatenatedOperation;
@@ -56,7 +57,7 @@ import static org.apache.sis.test.ReferencingAssert.*;
  * </ul>
  *
  * @author  Martin Desruisseaux (Geomatys)
- * @version 0.8
+ * @version 1.3
  * @since   0.7
  * @module
  */
@@ -352,4 +353,20 @@ public final strictfp class 
DefaultCoordinateOperationFactoryTest extends MathTr
                         CoordinateOperationFinderTest.expectedAGD66(false));
         validate();
     }
+
+    /**
+     * Verifies that requesting an unknown method throws {@link 
NoSuchIdentifierException}.
+     *
+     * @throws FactoryException if an unexpected error occurred.
+     */
+    @Test
+    public void testUnknownMethod() throws FactoryException {
+        try {
+            factory.getOperationMethod("I do not exist");
+            fail("Expected NoSuchIdentifierException");
+        } catch (NoSuchIdentifierException e) {
+            final String message = e.getMessage();
+            assertTrue(message, message.contains("I do not exist"));
+        }
+    }
 }
diff --git 
a/core/sis-utility/src/main/java/org/apache/sis/util/resources/IndexedResourceBundle.java
 
b/core/sis-utility/src/main/java/org/apache/sis/util/resources/IndexedResourceBundle.java
index 5beaaf851d..80d256013f 100644
--- 
a/core/sis-utility/src/main/java/org/apache/sis/util/resources/IndexedResourceBundle.java
+++ 
b/core/sis-utility/src/main/java/org/apache/sis/util/resources/IndexedResourceBundle.java
@@ -21,6 +21,7 @@ import java.io.BufferedInputStream;
 import java.io.DataInputStream;
 import java.io.IOException;
 import java.text.MessageFormat;
+import java.util.Arrays;
 import java.util.Map;
 import java.util.Enumeration;
 import java.util.Locale;
@@ -444,7 +445,7 @@ public class IndexedResourceBundle extends ResourceBundle 
implements Localized {
              */
             if (replacement != element) {
                 if (array == arguments) {
-                    array = array.clone();                  // Protect the 
user-provided array from change.
+                    array = Arrays.copyOf(array, array.length, Object[].class);
                 }
                 array[i] = replacement;
             }

Reply via email to