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 1649034  Provide more information in case of errors.
1649034 is described below

commit 1649034b09ad4b069166180c6d7eeb0472c4e015
Author: Martin Desruisseaux <martin.desruisse...@geomatys.com>
AuthorDate: Wed Feb 2 11:50:10 2022 +0100

    Provide more information in case of errors.
---
 .../java/org/apache/sis/image/PixelIterator.java   | 22 +++++++++++++++++++---
 .../org/apache/sis/util/resources/Messages.java    |  5 +++++
 .../apache/sis/util/resources/Messages.properties  |  1 +
 .../sis/util/resources/Messages_fr.properties      |  1 +
 .../apache/sis/internal/storage/inflater/LZW.java  |  1 +
 5 files changed, 27 insertions(+), 3 deletions(-)

diff --git 
a/core/sis-feature/src/main/java/org/apache/sis/image/PixelIterator.java 
b/core/sis-feature/src/main/java/org/apache/sis/image/PixelIterator.java
index 64f0f30..df2cb89 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/image/PixelIterator.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/image/PixelIterator.java
@@ -38,6 +38,7 @@ import java.awt.image.SinglePixelPackedSampleModel;
 import java.awt.image.RasterFormatException;
 import java.util.NoSuchElementException;
 import org.opengis.coverage.grid.SequenceType;
+import org.apache.sis.util.resources.Messages;
 import org.apache.sis.util.resources.Errors;
 import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.util.ArraysExt;
@@ -727,7 +728,7 @@ public class PixelIterator {
                 if (currentLowerY > py || py >= currentUpperY ||
                     currentLowerX > px || px >= currentUpperX)
                 {
-                    throw new 
RasterFormatException(Resources.format(Resources.Keys.IncompatibleTile_2, 
tileX, tileY));
+                    throw incompatibleTile();
                 }
             }
         }
@@ -799,7 +800,7 @@ public class PixelIterator {
                  * new row (in which case we need to move to the leftmost 
tile).
                  */
                 if (fetchTile() > y) {
-                    throw new 
RasterFormatException(Resources.format(Resources.Keys.IncompatibleTile_2, 
tileX, tileY));
+                    throw incompatibleTile();
                 }
             }
             changedRowOrTile();
@@ -827,6 +828,21 @@ public class PixelIterator {
     }
 
     /**
+     * Returns the exception to throw when the tile at index ({@link #tileX}, 
{@link #tileY})
+     * uses an incompatible sample model.
+     */
+    private RasterFormatException incompatibleTile() {
+        String message = Resources.format(Resources.Keys.IncompatibleTile_2, 
tileX, tileY);
+        if (image instanceof PlanarImage) {
+            final String inconsistency = ((PlanarImage) image).verify();
+            if (inconsistency != null) {
+                message = message + ' ' + 
Messages.format(Messages.Keys.PossibleInconsistency_1, inconsistency);
+            }
+        }
+        return new RasterFormatException(message);
+    }
+
+    /**
      * Fetches from the image a tile for the current {@link #tileX} and {@link 
#tileY} coordinates.
      * All fields prefixed by {@code current} are updated by this method. The 
caller is responsible
      * for updating the {@link #x} and {@link #y} fields.
@@ -845,7 +861,7 @@ public class PixelIterator {
             tile = image.getTile(tileX, tileY);
         }
         if (tile.getNumBands() != numBands || tile.getWidth() != tileWidth || 
tile.getHeight() != tileHeight) {
-            throw new 
RasterFormatException(Resources.format(Resources.Keys.IncompatibleTile_2, 
tileX, tileY));
+            throw incompatibleTile();
         }
         final int minX = tile.getMinX();
         final int minY = tile.getMinY();
diff --git 
a/core/sis-utility/src/main/java/org/apache/sis/util/resources/Messages.java 
b/core/sis-utility/src/main/java/org/apache/sis/util/resources/Messages.java
index de8aa4f..65ae9ec 100644
--- a/core/sis-utility/src/main/java/org/apache/sis/util/resources/Messages.java
+++ b/core/sis-utility/src/main/java/org/apache/sis/util/resources/Messages.java
@@ -197,6 +197,11 @@ public final class Messages extends IndexedResourceBundle {
         public static final short OptionalModuleNotFound_1 = 27;
 
         /**
+         * Possible inconsistency in “{0}”.
+         */
+        public static final short PossibleInconsistency_1 = 34;
+
+        /**
          * Property “{0}” is hidden by “{1}”.
          */
         public static final short PropertyHiddenBy_2 = 28;
diff --git 
a/core/sis-utility/src/main/java/org/apache/sis/util/resources/Messages.properties
 
b/core/sis-utility/src/main/java/org/apache/sis/util/resources/Messages.properties
index 5758f81..8b329f2 100644
--- 
a/core/sis-utility/src/main/java/org/apache/sis/util/resources/Messages.properties
+++ 
b/core/sis-utility/src/main/java/org/apache/sis/util/resources/Messages.properties
@@ -42,6 +42,7 @@ InsertDuration_2                 = Inserted {0} records in 
{1} seconds.
 JNDINotSpecified_1               = No object associated to the \u201c{0}\u201d 
JNDI name.
 LocalesDiscarded                 = Text were discarded for some locales.
 OptionalModuleNotFound_1         = Optional module \u201c{0}\u201d requested 
but not found.
+PossibleInconsistency_1          = Possible inconsistency in \u201c{0}\u201d.
 PropertyHiddenBy_2               = Property \u201c{0}\u201d is hidden by 
\u201c{1}\u201d.
 NonConformFormatting_1           = This \u201c{0}\u201d formatting is a 
departure from standard format.
 UnknownCodeList_1                = \u201c{0}\u201d is not the name of a known 
list of codes.
diff --git 
a/core/sis-utility/src/main/java/org/apache/sis/util/resources/Messages_fr.properties
 
b/core/sis-utility/src/main/java/org/apache/sis/util/resources/Messages_fr.properties
index 6177427..0669dd2 100644
--- 
a/core/sis-utility/src/main/java/org/apache/sis/util/resources/Messages_fr.properties
+++ 
b/core/sis-utility/src/main/java/org/apache/sis/util/resources/Messages_fr.properties
@@ -49,6 +49,7 @@ InsertDuration_2                 = {0} enregistrements ont 
\u00e9t\u00e9 ajout\u
 JNDINotSpecified_1               = Aucun objet n\u2019est associ\u00e9 au nom 
JNDI \u00ab\u202f{0}\u202f\u00bb.
 LocalesDiscarded                 = Des textes ont \u00e9t\u00e9 ignor\u00e9s 
pour certaines langues.
 OptionalModuleNotFound_1         = Le module optionnel 
\u00ab\u202f{0}\u202f\u00bb a \u00e9t\u00e9 demand\u00e9 mais n\u2019a pas 
\u00e9t\u00e9 trouv\u00e9.
+PossibleInconsistency_1           = Il y a possiblement une incoh\u00e9rence 
dans \u00ab\u202f{0}\u202f\u00bb.
 PropertyHiddenBy_2               = La propri\u00e9t\u00e9 
\u00ab\u202f{0}\u202f\u00bb est masqu\u00e9e par \u00ab\u202f{1}\u202f\u00bb.
 NonConformFormatting_1           = Cette \u00e9criture de 
\u00ab\u202f{0}\u202f\u00bb d\u00e9vie du format standard.
 UnknownCodeList_1                = \u00ab\u202f{0}\u202f\u00bb n\u2019est pas 
le nom d\u2019une liste de codes connue.
diff --git 
a/storage/sis-geotiff/src/main/java/org/apache/sis/internal/storage/inflater/LZW.java
 
b/storage/sis-geotiff/src/main/java/org/apache/sis/internal/storage/inflater/LZW.java
index cf7fe90..e6b5b12 100644
--- 
a/storage/sis-geotiff/src/main/java/org/apache/sis/internal/storage/inflater/LZW.java
+++ 
b/storage/sis-geotiff/src/main/java/org/apache/sis/internal/storage/inflater/LZW.java
@@ -241,6 +241,7 @@ final class LZW extends CompressionChannel {
                          * immediately after this code. If this is not the 
case, we will have an index
                          * out of bounds exception in the next iteration, 
which is caught above.
                          */
+                        assert nextAvailableEntry == sequencesForCodes.length 
: nextAvailableEntry;
                     }
                 }
                 /*

Reply via email to