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 4cb1bd2a20 Add a fallback when the identifier is null while formatting 
an error message.
4cb1bd2a20 is described below

commit 4cb1bd2a2033958f33d880dfc2f8a77a0299a83f
Author: Martin Desruisseaux <martin.desruisse...@geomatys.com>
AuthorDate: Wed Feb 5 16:10:04 2025 +0100

    Add a fallback when the identifier is null while formatting an error 
message.
---
 .../main/org/apache/sis/storage/geotiff/DataSubset.java   |  8 ++++++--
 .../main/org/apache/sis/storage/geotiff/GeoTiffStore.java | 15 +++++++++++++--
 .../apache/sis/storage/geotiff/ImageFileDirectory.java    |  3 +--
 3 files changed, 20 insertions(+), 6 deletions(-)

diff --git 
a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/DataSubset.java
 
b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/DataSubset.java
index d049111e8a..baab4b312c 100644
--- 
a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/DataSubset.java
+++ 
b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/DataSubset.java
@@ -190,8 +190,12 @@ class DataSubset extends TiledGridCoverage implements 
Localized {
      */
     @Override
     protected final GenericName getIdentifier() {
-        // Should never be empty (see `DataCube.getIdentifier()` contract).
-        return source.getIdentifier().get();
+        /*
+         * Should never be empty (see `DataCube.getIdentifier()` contract).
+         * Nevertheless use a fallback if the identifier is empty, because
+         * this method is invoked for formatting error messages.
+         */
+        return source.getIdentifier().orElseGet(() -> 
source.reader.store.createLocalName("overview"));
     }
 
     /**
diff --git 
a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/GeoTiffStore.java
 
b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/GeoTiffStore.java
index 76303e2e81..360332cd75 100644
--- 
a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/GeoTiffStore.java
+++ 
b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/GeoTiffStore.java
@@ -273,10 +273,10 @@ public class GeoTiffStore extends DataStore implements 
Aggregate {
     }
 
     /**
-     * Returns the namespace to use in identifier of components, or {@code 
null} if none.
+     * Returns the namespace to use in component identifiers, or {@code null} 
if none.
      * This method must be invoked inside a block synchronized on {@code this}.
      */
-    final NameSpace namespace() {
+    private NameSpace namespace() {
         @SuppressWarnings("LocalVariableHidesMemberVariable")
         final Reader reader = this.reader;
         if (!isNamespaceSet && reader != null) {
@@ -299,6 +299,17 @@ public class GeoTiffStore extends DataStore implements 
Aggregate {
         return namespace;
     }
 
+    /**
+     * Creates a name in the namespace of this store.
+     * This method must be invoked inside a block synchronized on {@code this}.
+     *
+     * @param  tip  the tip of the name to create.
+     * @return a name in the scope of this store.
+     */
+    final GenericName createLocalName(final String tip) {
+        return reader.nameFactory.createLocalName(namespace(), tip);
+    }
+
     /**
      * Opens access to listeners for {@link ImageFileDirectory}.
      */
diff --git 
a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/ImageFileDirectory.java
 
b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/ImageFileDirectory.java
index bb82527122..61a7cc4850 100644
--- 
a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/ImageFileDirectory.java
+++ 
b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/ImageFileDirectory.java
@@ -488,8 +488,7 @@ final class ImageFileDirectory extends DataCube {
                     // Should not happen because `setOverviewIdentifier(…)` 
should have been invoked.
                     return Optional.empty();
                 }
-                final String tip = String.valueOf(index + 1);
-                GenericName name = 
reader.nameFactory.createLocalName(reader.store.namespace(), tip);
+                GenericName name = 
reader.store.createLocalName(String.valueOf(index + 1));
                 name = name.toFullyQualifiedName();     // Because "1" alone 
is not very informative.
                 final var source = new SchemaModifier.Source(reader.store, 
index, getDataType());
                 identifier = reader.store.customizer.customize(source, name);

Reply via email to