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 9c99fd50edd9d8d039d9300f5fc255bac7cde320
Author: Martin Desruisseaux <martin.desruisse...@geomatys.com>
AuthorDate: Tue Nov 9 18:52:55 2021 +0100

    Exception throws by `ComputedImage` in case of invalid tile index needs to 
be consistent with exception expected by `GridEvaluator.apply(…)`.
---
 .../org/apache/sis/gui/map/ValuesUnderCursor.java  |  5 +----
 .../java/org/apache/sis/image/ComputedImage.java   | 25 +++++++++++++++++-----
 2 files changed, 21 insertions(+), 9 deletions(-)

diff --git 
a/application/sis-javafx/src/main/java/org/apache/sis/gui/map/ValuesUnderCursor.java
 
b/application/sis-javafx/src/main/java/org/apache/sis/gui/map/ValuesUnderCursor.java
index fda3292..6e8d291 100644
--- 
a/application/sis-javafx/src/main/java/org/apache/sis/gui/map/ValuesUnderCursor.java
+++ 
b/application/sis-javafx/src/main/java/org/apache/sis/gui/map/ValuesUnderCursor.java
@@ -38,7 +38,6 @@ import javafx.scene.control.MenuItem;
 import javax.measure.Unit;
 import org.opengis.geometry.DirectPosition;
 import org.opengis.coverage.CannotEvaluateException;
-import org.opengis.coverage.PointOutsideCoverageException;
 import org.opengis.metadata.content.TransferFunctionType;
 import org.apache.sis.referencing.operation.transform.TransferFunction;
 import org.apache.sis.gui.coverage.CoverageCanvas;
@@ -67,7 +66,7 @@ import org.apache.sis.util.resources.Vocabulary;
  * {@code ValuesUnderCursor} methods will be invoked from JavaFX thread.
  *
  * @author  Martin Desruisseaux (Geomatys)
- * @version 1.1
+ * @version 1.2
  * @since   1.1
  * @module
  */
@@ -521,8 +520,6 @@ public abstract class ValuesUnderCursor {
                             }
                             return buffer.toString();
                         }
-                    } catch (PointOutsideCoverageException e) {
-                        // Ignore.
                     } catch (CannotEvaluateException e) {
                         recoverableException("evaluate", e);
                     }
diff --git 
a/core/sis-feature/src/main/java/org/apache/sis/image/ComputedImage.java 
b/core/sis-feature/src/main/java/org/apache/sis/image/ComputedImage.java
index 8d8d847..12d3b58 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/image/ComputedImage.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/image/ComputedImage.java
@@ -115,7 +115,7 @@ import org.apache.sis.internal.feature.Resources;
  * if the change to dirty state happened after the call to {@link 
#getTile(int, int) getTile(…)}.</p>
  *
  * @author  Martin Desruisseaux (Geomatys)
- * @version 1.1
+ * @version 1.2
  * @since   1.1
  * @module
  */
@@ -414,6 +414,21 @@ public abstract class ComputedImage extends PlanarImage 
implements Disposable {
     }
 
     /**
+     * Verifies that an index is inside the expected range of tile indices.
+     * If the index is out of bounds, then this method throws an {@code 
IndexOutOfBoundsException}
+     * for consistency with {@link java.awt.image.BufferedImage#getTile(int, 
int)} public contract.
+     *
+     * @throws IndexOutOfBoundsException if the given tile index is out of 
bounds.
+     */
+    private static void checkTileIndex(final String name, final int min, final 
int count, final int value) {
+        final int max = min + count;
+        if (value < min || value >= max) {
+            throw new IndexOutOfBoundsException(Errors.format(
+                    Errors.Keys.ValueOutOfRange_4, name, min, max - 1, value));
+        }
+    }
+
+    /**
      * Returns a tile of this image, computing it when needed.
      * This method performs the first of the following actions that apply:
      *
@@ -436,7 +451,7 @@ public abstract class ComputedImage extends PlanarImage 
implements Disposable {
      * @param  tileX  the column index of the tile to get.
      * @param  tileY  the row index of the tile to get.
      * @return the tile at the given index (never null).
-     * @throws IllegalArgumentException if a given tile index is out of bounds.
+     * @throws IndexOutOfBoundsException if a given tile index is out of 
bounds.
      * @throws ImagingOpException if an error occurred while computing the 
image.
      */
     @Override
@@ -451,9 +466,8 @@ public abstract class ComputedImage extends PlanarImage 
implements Disposable {
              * We will need to check the cache again after we got the lock in 
case computation has
              * happened in the short time between above check and lock 
acquisition.
              */
-            int min;
-            ArgumentChecks.ensureBetween("tileX", (min = getMinTileX()), min + 
getNumXTiles() - 1, tileX);
-            ArgumentChecks.ensureBetween("tileY", (min = getMinTileY()), min + 
getNumYTiles() - 1, tileY);
+            checkTileIndex("tileX", getMinTileX(), getNumXTiles(), tileX);
+            checkTileIndex("tileY", getMinTileY(), getNumYTiles(), tileY);
             Throwable error = null;
             final Cache.Handler<Raster> handler = cache.lock(key);
             try {
@@ -466,6 +480,7 @@ public abstract class ComputedImage extends PlanarImage 
implements Disposable {
                      * by that destination. The write operation shall happen 
between `getWritableTile(…)`
                      * and `releaseWritableTile(…)` method calls.
                      */
+                    int min;
                     final WritableRenderedImage destination = 
this.destination;     // Protect from change (paranoiac).
                     final boolean writeInDestination = (destination != null)
                             && (tileX >= (min = destination.getMinTileX()) && 
tileX < min + destination.getNumXTiles())

Reply via email to