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 2e0a10bfafce259d504a718d9acb4e9436d0f802
Author: Martin Desruisseaux <martin.desruisse...@geomatys.com>
AuthorDate: Wed Feb 2 14:22:23 2022 +0100

    Make error message more understandable.
---
 .../java/org/apache/sis/internal/geotiff/Resources.java    |  4 ++--
 .../org/apache/sis/internal/geotiff/Resources.properties   |  2 +-
 .../apache/sis/internal/geotiff/Resources_fr.properties    |  2 +-
 .../java/org/apache/sis/storage/geotiff/CRSBuilder.java    | 14 +++++++++++++-
 .../org/apache/sis/storage/geotiff/ImageFileDirectory.java | 13 +++++++++----
 5 files changed, 26 insertions(+), 9 deletions(-)

diff --git 
a/storage/sis-geotiff/src/main/java/org/apache/sis/internal/geotiff/Resources.java
 
b/storage/sis-geotiff/src/main/java/org/apache/sis/internal/geotiff/Resources.java
index 538bc36..efcc677 100644
--- 
a/storage/sis-geotiff/src/main/java/org/apache/sis/internal/geotiff/Resources.java
+++ 
b/storage/sis-geotiff/src/main/java/org/apache/sis/internal/geotiff/Resources.java
@@ -127,8 +127,8 @@ public final class Resources extends IndexedResourceBundle {
         public static final short ListTooShort_3 = 10;
 
         /**
-         * TIFF tags “{0}” and “{1}” have values of different lengths. Found 
“{2}” and “{3}” elements
-         * respectively.
+         * TIFF tag “{0}” has a list of {2} elements, but {3} elements were 
expected according tag
+         * “{1}”.
          */
         public static final short MismatchedLength_4 = 11;
 
diff --git 
a/storage/sis-geotiff/src/main/java/org/apache/sis/internal/geotiff/Resources.properties
 
b/storage/sis-geotiff/src/main/java/org/apache/sis/internal/geotiff/Resources.properties
index 6eb61a8..50df181 100644
--- 
a/storage/sis-geotiff/src/main/java/org/apache/sis/internal/geotiff/Resources.properties
+++ 
b/storage/sis-geotiff/src/main/java/org/apache/sis/internal/geotiff/Resources.properties
@@ -32,7 +32,7 @@ InconsistentMapProjParameter_4    = Map projection parameter 
\u201c{2}\u201d wil
 InconsistentTileStrip_1           = TIFF image \u201c{0}\u201d shall be either 
tiled or organized into strips.
 InvalidGeoValue_2                 = \u201c{1}\u201d is not a valid value for 
the \u201c{0}\u201d GeoTIFF key.
 ListTooShort_3                    = TIFF tag \u201c{0}\u201d shall contain at 
least {1} values but found only {2}.
-MismatchedLength_4                = TIFF tags \u201c{0}\u201d and 
\u201c{1}\u201d have values of different lengths. Found \u201c{2}\u201d and 
\u201c{3}\u201d elements respectively.
+MismatchedLength_4                = TIFF tag \u201c{0}\u201d has a list of {2} 
elements, but {3} elements were expected according tag \u201c{1}\u201d.
 MissingGeoValue_1                 = No value has been found for the 
\u201c{0}\u201d GeoTIFF key.
 MissingValue_2                    = Can not read TIFF image from 
\u201c{0}\u201d because the \u201c{1}\u201d tag is missing.
 NotTheEpsgValue_5                 = The file defines \u201c{2}\u201d with 
value {3}{4}, but that value should be {1}{4} according parent definition ({0}).
diff --git 
a/storage/sis-geotiff/src/main/java/org/apache/sis/internal/geotiff/Resources_fr.properties
 
b/storage/sis-geotiff/src/main/java/org/apache/sis/internal/geotiff/Resources_fr.properties
index 342da87..f668385 100644
--- 
a/storage/sis-geotiff/src/main/java/org/apache/sis/internal/geotiff/Resources_fr.properties
+++ 
b/storage/sis-geotiff/src/main/java/org/apache/sis/internal/geotiff/Resources_fr.properties
@@ -37,7 +37,7 @@ InconsistentMapProjParameter_4    = Le param\u00e8tre de 
projection cartographiq
 InconsistentTileStrip_1           = L\u2019image TIFF 
\u00ab\u202f{0}\u202f\u00bb doit \u00eatre soit tuil\u00e9e, soit 
organis\u00e9e par bandes.
 InvalidGeoValue_2                 = La valeur \u00ab\u202f{1}\u202f\u00bb 
n\u2019est pas valide pour la cl\u00e9 GeoTIFF \u00ab\u202f{0}\u202f\u00bb.
 ListTooShort_3                    = Le tag TIFF \u00ab\u202f{0}\u202f\u00bb 
devrait contenir au moins {1} valeurs alors qu\u2019on n\u2019en a trouv\u00e9 
que {2}.
-MismatchedLength_4                = Les tags TIFF \u00ab\u202f{0}\u202f\u00bb 
et \u00ab\u202f{1}\u202f\u00bb contiennent des valeurs de longueurs 
diff\u00e9rentes. On a trouv\u00e9 {2} et {3} \u00e9l\u00e9ments respectivement.
+MismatchedLength_4                = Le tag TIFF \u00ab\u202f{0}\u202f\u00bb 
contient une liste de {2} \u00e9l\u00e9ments, alors qu\u2019on en attendait {3} 
d\u2019apr\u00e8s le tag \u00ab\u202f{1}\u202f\u00bb.
 MissingGeoValue_1                 = Aucune valeur n\u2019a \u00e9t\u00e9 
trouv\u00e9e pour la cl\u00e9 GeoTIFF \u00ab\u202f{0}\u202f\u00bb.
 MissingValue_2                    = Ne peut pas lire l\u2019image TIFF 
provenant de \u00ab\u202f{0}\u202f\u00bb car le tag \u00ab\u202f{1}\u202f\u00bb 
est manquant.
 NotTheEpsgValue_5                 = Le fichier d\u00e9finit 
\u00ab\u202f{2}\u202f\u00bb avec la valeur {3}{4}, mais cette valeur devrait 
\u00eatre {1}{4} pour \u00eatre en accord avec la d\u00e9finition du parent {0}.
diff --git 
a/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/CRSBuilder.java
 
b/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/CRSBuilder.java
index af17277..c62e197 100644
--- 
a/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/CRSBuilder.java
+++ 
b/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/CRSBuilder.java
@@ -17,7 +17,9 @@
 package org.apache.sis.storage.geotiff;
 
 import java.util.Arrays;
+import java.util.Set;
 import java.util.Map;
+import java.util.HashSet;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Collections;
@@ -152,6 +154,13 @@ final class CRSBuilder extends ReferencingFactoryContainer 
{
     private final Map<Short,Object> geoKeys;
 
     /**
+     * Missing GeoKeys, used for avoiding to report the same warning twice.
+     *
+     * @see #missingValue(short)
+     */
+    private final Set<String> missingGeoKeys;
+
+    /**
      * Name of the last object created. This is used by {@link 
#properties(Object)} for reusing existing instance
      * if possible. This is useful in GeoTIFF files since the same name is 
used for different geodetic components,
      * for example the datum and the ellipsoid.
@@ -186,6 +195,7 @@ final class CRSBuilder extends ReferencingFactoryContainer {
     CRSBuilder(final Reader reader) {
         this.reader = reader;
         geoKeys = new HashMap<>(32);
+        missingGeoKeys = new HashSet<>();
     }
 
     /**
@@ -360,7 +370,9 @@ final class CRSBuilder extends ReferencingFactoryContainer {
      */
     final String missingValue(final short key) {
         final String name = GeoKeys.name(key);
-        warning(Resources.Keys.MissingGeoValue_1, name);
+        if (missingGeoKeys.add(name)) {
+            warning(Resources.Keys.MissingGeoValue_1, name);
+        }
         return name;
     }
 
diff --git 
a/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/ImageFileDirectory.java
 
b/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/ImageFileDirectory.java
index e88f5e9..147ad25 100644
--- 
a/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/ImageFileDirectory.java
+++ 
b/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/ImageFileDirectory.java
@@ -1277,7 +1277,7 @@ final class ImageFileDirectory extends DataCube {
          * Report an error if the tile offset and tile byte count vectors do 
not have the same length.
          * Then ensure that the number of tiles is equal to the expected 
number.
          */
-        ensureSameLength(offsetsTag, byteCountsTag, tileOffsets.size(), 
tileByteCounts.size());
+        ensureSameLength(byteCountsTag, offsetsTag, tileByteCounts.size(), 
tileOffsets.size());
         long expectedCount = getNumTiles();
         if (isPlanar) {
             expectedCount = Math.multiplyExact(expectedCount, samplesPerPixel);
@@ -1710,10 +1710,15 @@ final class ImageFileDirectory extends DataCube {
 
     /**
      * Verifies that the given tags have the same length and reports a warning 
if they do not.
+     *
+     * @param  tag1      the TIFF tag with inconsistent length.
+     * @param  tag2      the TIFF tag used as a reference.
+     * @param  actual    length of list associated to {@code tag1}.
+     * @param  expected  length of list associated to {@code tag2}.
      */
-    private void ensureSameLength(final short tag1, final short tag2, final 
int length1, final int length2) {
-        if (length1 != length2) {
-            warning(Level.WARNING, Resources.Keys.MismatchedLength_4, 
Tags.name(tag1), Tags.name(tag2), length1, length2);
+    private void ensureSameLength(final short tag1, final short tag2, final 
int actual, final int expected) {
+        if (actual != expected) {
+            warning(Level.WARNING, Resources.Keys.MismatchedLength_4, 
Tags.name(tag1), Tags.name(tag2), actual, expected);
         }
     }
 

Reply via email to