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 e76f36ff59 Avoid a NullPointerException when a GeoTIFF file has 
incomplete georeferencing information.
e76f36ff59 is described below

commit e76f36ff5998ebb23c9b54762ed180ba64169597
Author: Martin Desruisseaux <martin.desruisse...@geomatys.com>
AuthorDate: Fri Dec 6 17:37:20 2024 +0100

    Avoid a NullPointerException when a GeoTIFF file has incomplete 
georeferencing information.
---
 .../main/org/apache/sis/storage/geotiff/ImageFileDirectory.java     | 6 +++---
 .../org/apache/sis/storage/geotiff/reader/GridGeometryBuilder.java  | 6 ++++--
 .../main/org/apache/sis/storage/geotiff/reader/Localization.java    | 1 +
 3 files changed, 8 insertions(+), 5 deletions(-)

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 887ce92d68..181e8c3aa8 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
@@ -1350,11 +1350,11 @@ final class ImageFileDirectory extends DataCube {
                     filename(), expectedCount, actualCount));
         }
         /*
-         * If a "grid to CRS" conversion has been specified with only the 
scale factor, we need to compute
-         * the translation terms now.
+         * If a "grid to CRS" conversion has been specified with only the 
scale factor,
+         * we need to compute the translation terms now.
          */
         if (referencing != null && !referencing.validateMandatoryTags()) {
-            throw missingTag((short) TAG_MODEL_TIE_POINT);
+            listeners.warning(missingTag((short) TAG_MODEL_TIE_POINT));
         }
         isValidated = true;
         return true;
diff --git 
a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/reader/GridGeometryBuilder.java
 
b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/reader/GridGeometryBuilder.java
index e8713e69d7..56e3e3835d 100644
--- 
a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/reader/GridGeometryBuilder.java
+++ 
b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/reader/GridGeometryBuilder.java
@@ -194,10 +194,12 @@ public final class GridGeometryBuilder extends 
GeoKeysLoader {
      * @see ImageFileDirectory#validateMandatoryTags()
      */
     public boolean validateMandatoryTags() {
+        @SuppressWarnings("LocalVariableHidesMemberVariable")
         final MatrixSIS affine = this.affine;
         if (affine == null || completeMatrixSpecified) {
             return true;
         }
+        @SuppressWarnings("LocalVariableHidesMemberVariable")
         final Vector modelTiePoints = this.modelTiePoints;
         if (modelTiePoints != null) {
             /*
@@ -296,10 +298,10 @@ public final class GridGeometryBuilder extends 
GeoKeysLoader {
         final MathTransformFactory factory = 
DefaultMathTransformFactory.provider();
         GridGeometry gridGeometry;
         try {
-            MathTransform gridToCRS;
+            MathTransform gridToCRS = null;
             if (affine != null) {
                 gridToCRS = 
factory.createAffineTransform(Matrices.resizeAffine(affine, ++n, n));
-            } else {
+            } else if (modelTiePoints != null) {
                 pixelIsPoint = true;
                 gridToCRS = Localization.nonLinear(modelTiePoints);
                 gridToCRS = factory.createPassThroughTransform(0, gridToCRS, n 
- 2);
diff --git 
a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/reader/Localization.java
 
b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/reader/Localization.java
index 4d8cbffd0b..605771cb00 100644
--- 
a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/reader/Localization.java
+++ 
b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/reader/Localization.java
@@ -77,6 +77,7 @@ final class Localization {
      *
      * @param  modelTiePoints  the model tie points read from GeoTIFF file.
      * @param  addTo           if non-null, add the transform result to this 
map.
+     * @return the "grid to CRS" transform backed by the localization grid.
      */
     private static MathTransform localizationGrid(final Vector modelTiePoints, 
final Map<Envelope,MathTransform> addTo)
             throws FactoryException, TransformException

Reply via email to