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 74af00d68a55462c4de8d0c94a146a77ad1b3c9e
Author: Martin Desruisseaux <[email protected]>
AuthorDate: Thu Jan 3 19:33:23 2019 +0100

    Consolidation of exception handling.
---
 .../org/apache/sis/coverage/grid/GridExtent.java   |   4 +-
 .../org/apache/sis/coverage/grid/GridGeometry.java | 109 ++++++++++-----------
 ...tion.java => IllegalGridGeometryException.java} |  27 ++---
 .../grid/IncompleteGridGeometryException.java      |  10 --
 .../sis/coverage/grid/SubgridCalculator.java       |  38 ++++---
 .../org/apache/sis/internal/raster/Resources.java  |   5 +
 .../sis/internal/raster/Resources.properties       |   1 +
 .../sis/internal/raster/Resources_fr.properties    |   1 +
 .../apache/sis/coverage/grid/GridGeometryTest.java |   4 +-
 .../java/org/apache/sis/internal/netcdf/Grid.java  |   4 +-
 10 files changed, 100 insertions(+), 103 deletions(-)

diff --git 
a/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridExtent.java 
b/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridExtent.java
index 4c6318e..5b278dd 100644
--- a/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridExtent.java
+++ b/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridExtent.java
@@ -164,9 +164,11 @@ public class GridExtent implements Serializable {
     /**
      * Verifies that the given array (if non-null) contains no duplicated 
values, then returns a copy of that array.
      * The returned copy may be shared by many {@code GridExtent} instances. 
Consequently it shall not be modified.
+     *
+     * @throws IllegalArgumentException if the given array contains duplicated 
elements.
      */
     @SuppressWarnings("ReturnOfCollectionOrArrayField")
-    private static DimensionNameType[] validateAxisTypes(DimensionNameType[] 
types) {
+    private static DimensionNameType[] validateAxisTypes(DimensionNameType[] 
types) throws IllegalArgumentException {
         if (types == null) {
             return null;
         }
diff --git 
a/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridGeometry.java 
b/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridGeometry.java
index 0b2644d..4001abb 100644
--- 
a/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridGeometry.java
+++ 
b/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridGeometry.java
@@ -237,39 +237,34 @@ public class GridGeometry implements Serializable {
      * @param  extent   the new extent for the grid geometry to construct, or 
{@code null} if none.
      * @param  toOther  transform from this grid coordinates to {@code other} 
grid coordinates, or {@code null} if none.
      * @throws NullPointerException if {@code extent} is {@code null} and the 
other grid geometry contains no other information.
-     * @throws InvalidGridGeometryException if the math transform can not 
compute the geospatial envelope from the grid extent.
+     * @throws TransformException if the math transform can not compute the 
geospatial envelope from the grid extent.
      *
      * @see #subExtent(Envelope)
      * @see #subgrid(Envelope, double...)
      */
-    GridGeometry(final GridGeometry other, final GridExtent extent, final 
MathTransform toOther) {
-        ArgumentChecks.ensureNonNull("other", other);
+    GridGeometry(final GridGeometry other, final GridExtent extent, final 
MathTransform toOther) throws TransformException {
         final int dimension = other.getDimension();
         this.extent = extent;
         ensureDimensionMatches(dimension, extent);
-        try {
-            if (toOther == null || toOther.isIdentity()) {
-                gridToCRS   = other.gridToCRS;
-                cornerToCRS = other.cornerToCRS;
-                resolution  = other.resolution;
-                nonLinears  = other.nonLinears;
-            } else {
-                gridToCRS   = MathTransforms.concatenate(toOther, 
other.gridToCRS);
-                cornerToCRS = MathTransforms.concatenate(toOther, 
other.cornerToCRS);
-                resolution  = resolution(gridToCRS, extent);
-                nonLinears  = findNonLinearTargets(gridToCRS);
-            }
-            ImmutableEnvelope envelope = other.envelope;            // We will 
share the same instance if possible.
-            ImmutableEnvelope computed = computeEnvelope(gridToCRS, (envelope 
!= null) ? envelope.getCoordinateReferenceSystem() : null, envelope);
-            if (computed == null || !computed.equals(envelope)) {
-                envelope = computed;
-            }
-            this.envelope = envelope;
-            if (envelope == null && gridToCRS == null) {
-                ArgumentChecks.ensureNonNull("extent", extent);
-            }
-        } catch (TransformException e) {
-            throw new InvalidGridGeometryException(e);
+        if (toOther == null || toOther.isIdentity()) {
+            gridToCRS   = other.gridToCRS;
+            cornerToCRS = other.cornerToCRS;
+            resolution  = other.resolution;
+            nonLinears  = other.nonLinears;
+        } else {
+            gridToCRS   = MathTransforms.concatenate(toOther, other.gridToCRS);
+            cornerToCRS = MathTransforms.concatenate(toOther, 
other.cornerToCRS);
+            resolution  = resolution(gridToCRS, extent);
+            nonLinears  = findNonLinearTargets(gridToCRS);
+        }
+        ImmutableEnvelope envelope = other.envelope;            // We will 
share the same instance if possible.
+        ImmutableEnvelope computed = computeEnvelope(gridToCRS, (envelope != 
null) ? envelope.getCoordinateReferenceSystem() : null, envelope);
+        if (computed == null || !computed.equals(envelope)) {
+            envelope = computed;
+        }
+        this.envelope = envelope;
+        if (envelope == null && gridToCRS == null) {
+            ArgumentChecks.ensureNonNull("extent", extent);
         }
     }
 
@@ -312,7 +307,7 @@ public class GridGeometry implements Serializable {
      * @param  crs        the coordinate reference system of the "real world" 
coordinates, or {@code null} if unknown.
      * @throws NullPointerException if {@code extent}, {@code gridToCRS} and 
{@code crs} arguments are all null.
      * @throws MismatchedDimensionException if the math transform and the CRS 
do not have consistent dimensions.
-     * @throws InvalidGridGeometryException if the math transform can not 
compute the geospatial envelope or resolution from the grid extent.
+     * @throws IllegalGridGeometryException if the math transform can not 
compute the geospatial envelope or resolution from the grid extent.
      */
     public GridGeometry(final GridExtent extent, final PixelInCell anchor, 
final MathTransform gridToCRS, final CoordinateReferenceSystem crs) {
         if (gridToCRS != null) {
@@ -329,7 +324,7 @@ public class GridGeometry implements Serializable {
             this.resolution  = resolution(gridToCRS, extent);           // 
'gridToCRS' or 'cornerToCRS' does not matter here.
             this.nonLinears  = findNonLinearTargets(gridToCRS);
         } catch (TransformException e) {
-            throw new InvalidGridGeometryException(e);
+            throw new IllegalGridGeometryException(e, "gridToCRS");
         }
     }
 
@@ -395,7 +390,7 @@ public class GridGeometry implements Serializable {
      *                    There is no guarantees that the envelope actually 
stored in the {@code GridGeometry}
      *                    will be equal to this specified envelope.
      * @param  rounding   controls behavior of rounding from floating point 
values to integers.
-     * @throws InvalidGridGeometryException if the math transform can not 
compute the grid extent or the resolution.
+     * @throws IllegalGridGeometryException if the math transform can not 
compute the grid extent or the resolution.
      */
     @SuppressWarnings("null")
     public GridGeometry(final PixelInCell anchor, final MathTransform 
gridToCRS, final Envelope envelope, final GridRoundingMode rounding) {
@@ -416,7 +411,7 @@ public class GridGeometry implements Serializable {
                 extent = new GridExtent(env, GridRoundingMode.NEAREST, null, 
null, null);
                 env = extent.toCRS(cornerToCRS, gridToCRS);         // 
'gridToCRS' specified by the user, not 'this.gridToCRS'.
             } catch (TransformException e) {
-                throw new InvalidGridGeometryException(e);
+                throw new IllegalGridGeometryException(e, "gridToCRS");
             }
             
env.setCoordinateReferenceSystem(envelope.getCoordinateReferenceSystem());
             this.envelope = new ImmutableEnvelope(env);
@@ -596,7 +591,7 @@ public class GridGeometry implements Serializable {
      * @throws IncompleteGridGeometryException if this grid geometry has no 
CRS —
      *         i.e. <code>{@linkplain #isDefined isDefined}({@linkplain 
#CRS})</code> returned {@code false}.
      */
-    public CoordinateReferenceSystem getCoordinateReferenceSystem() throws 
IncompleteGridGeometryException {
+    public CoordinateReferenceSystem getCoordinateReferenceSystem() {
         if (envelope != null) {
             final CoordinateReferenceSystem crs = 
envelope.getCoordinateReferenceSystem();
             if (crs != null) return crs;
@@ -617,7 +612,7 @@ public class GridGeometry implements Serializable {
      * @throws IncompleteGridGeometryException if this grid geometry has no 
envelope —
      *         i.e. <code>{@linkplain #isDefined(int) isDefined}({@linkplain 
#ENVELOPE})</code> returned {@code false}.
      */
-    public Envelope getEnvelope() throws IncompleteGridGeometryException {
+    public Envelope getEnvelope() {
         if (envelope != null && !envelope.isAllNaN()) {
             return envelope;
         }
@@ -637,7 +632,7 @@ public class GridGeometry implements Serializable {
      * @throws IncompleteGridGeometryException if this grid geometry has no 
extent —
      *         i.e. <code>{@linkplain #isDefined(int) isDefined}({@linkplain 
#EXTENT})</code> returned {@code false}.
      */
-    public GridExtent getExtent() throws IncompleteGridGeometryException {
+    public GridExtent getExtent() {
         if (extent != null) {
             return extent;
         }
@@ -663,17 +658,17 @@ public class GridGeometry implements Serializable {
      * @param  areaOfInterest  the desired spatiotemporal region in any CRS 
(transformations will be applied as needed).
      * @return a grid extent of the same dimension than the grid geometry 
which intersects the given area of interest.
      * @throws IncompleteGridGeometryException if this grid geometry has no 
extent or no "grid to CRS" transform.
-     * @throws InvalidGridGeometryException if an error occurred while 
converting the envelope coordinates to grid coordinates.
+     * @throws IllegalGridGeometryException if an error occurred while 
converting the envelope coordinates to grid coordinates.
      *
      * @see #subgrid(Envelope, double...)
      */
-    public GridExtent subExtent(final Envelope areaOfInterest) throws 
IncompleteGridGeometryException {
+    public GridExtent subExtent(final Envelope areaOfInterest) {
         ArgumentChecks.ensureNonNull("areaOfInterest", areaOfInterest);
         requireGridToCRS();
         try {
             return new SubgridCalculator(this, cornerToCRS, areaOfInterest, 
null).extent;
-        } catch (TransformException e) {
-            throw new InvalidGridGeometryException(e);
+        } catch (FactoryException | TransformException e) {
+            throw new IllegalGridGeometryException(e, "areaOfInterest");
         }
     }
 
@@ -690,8 +685,9 @@ public class GridGeometry implements Serializable {
      *
      * @param  slicePoint   the coordinates where to get a slice.
      * @return a slice of the grid extent at the given slice point.
-     * @throws InvalidGridGeometryException if an error occurred while 
converting the point coordinates to grid coordinates.
+     * @throws IncompleteGridGeometryException if this grid geometry has no 
extent or no "grid to CRS" transform.
      * @throws PointOutsideCoverageException if the given point is outside the 
grid extent.
+     * @throws IllegalGridGeometryException if an error occurred while 
converting the point coordinates to grid coordinates.
      *
      * @see #slice(DirectPosition)
      */
@@ -701,7 +697,7 @@ public class GridGeometry implements Serializable {
         try {
             return new SubgridCalculator(this, cornerToCRS, slicePoint).extent;
         } catch (TransformException e) {
-            throw new InvalidGridGeometryException(e);
+            throw new IllegalGridGeometryException(e, "slicePoint");
         }
     }
 
@@ -737,7 +733,7 @@ public class GridGeometry implements Serializable {
      * @throws IncompleteGridGeometryException if this grid geometry has no 
transform —
      *         i.e. <code>{@linkplain #isDefined(int) isDefined}({@linkplain 
#GRID_TO_CRS})</code> returned {@code false}.
      */
-    public MathTransform getGridToCRS(final PixelInCell anchor) throws 
IncompleteGridGeometryException {
+    public MathTransform getGridToCRS(final PixelInCell anchor) {
         final MathTransform mt;
         if (PixelInCell.CELL_CENTER.equals(anchor)) {
             mt = gridToCRS;
@@ -805,7 +801,7 @@ public class GridGeometry implements Serializable {
      * <p>Note that for this computation, it does not matter if {@code 
gridToCRS} is the user-specified
      * transform or the {@code this.gridToCRS} field value; both should 
produce equivalent results.</p>
      */
-    static double[] resolution(final MathTransform gridToCRS, final GridExtent 
domain) throws TransformException {
+    static double[] resolution(final MathTransform gridToCRS, final GridExtent 
domain) {
         final Matrix matrix = MathTransforms.getMatrix(gridToCRS);
         if (matrix != null) {
             return resolution(matrix, 1);
@@ -1004,7 +1000,7 @@ public class GridGeometry implements Serializable {
      * @see #getResolution(boolean)
      * @see #getGridToCRS(PixelInCell)
      */
-    public boolean isDefined(final int bitmask) throws 
IllegalArgumentException {
+    public boolean isDefined(final int bitmask) {
         if ((bitmask & ~(CRS | ENVELOPE | EXTENT | GRID_TO_CRS | RESOLUTION)) 
!= 0) {
             throw new IllegalArgumentException(Errors.format(
                     Errors.Keys.IllegalArgumentValue_2, "bitmask", bitmask));
@@ -1036,21 +1032,20 @@ public class GridGeometry implements Serializable {
      *                           or {@code null} or an empty array if no 
sub-sampling is desired.
      * @return a grid geometry over the specified sub-region of this grid 
geometry with the specified resolution.
      * @throws IncompleteGridGeometryException if this grid geometry has no 
extent or no "grid to CRS" transform.
-     * @throws InvalidGridGeometryException if an error occurred while 
converting the envelope coordinates to grid coordinates.
+     * @throws IllegalGridGeometryException if an error occurred while 
converting the envelope coordinates to grid coordinates.
      *
      * @see #subExtent(Envelope)
      * @see GridExtent#subsample(int[])
      */
     public GridGeometry subgrid(final Envelope areaOfInterest, double... 
targetResolution) {
         requireGridToCRS();
-        final SubgridCalculator sub;
         try {
-            sub = new SubgridCalculator(this, cornerToCRS, areaOfInterest, 
targetResolution);
-        } catch (TransformException e) {
-            throw new InvalidGridGeometryException(e);
-        }
-        if (sub.toSubsampled != null || sub.extent != extent) {
-            return new GridGeometry(this, sub.extent, sub.toSubsampled);
+            final SubgridCalculator sub = new SubgridCalculator(this, 
cornerToCRS, areaOfInterest, targetResolution);
+            if (sub.toSubsampled != null || sub.extent != extent) {
+                return new GridGeometry(this, sub.extent, sub.toSubsampled);
+            }
+        } catch (FactoryException | TransformException e) {
+            throw new IllegalGridGeometryException(e, "areaOfInterest");
         }
         return this;
     }
@@ -1078,7 +1073,7 @@ public class GridGeometry implements Serializable {
      *
      * @param  slicePoint   the coordinates where to get a slice.
      * @return a slice of this grid geometry at the given slice point. May be 
{@code this}.
-     * @throws InvalidGridGeometryException if an error occurred while 
converting the point coordinates to grid coordinates.
+     * @throws IllegalGridGeometryException if an error occurred while 
converting the point coordinates to grid coordinates.
      * @throws PointOutsideCoverageException if the given point is outside the 
grid extent.
      *
      * @see #subExtent(DirectPosition)
@@ -1086,13 +1081,15 @@ public class GridGeometry implements Serializable {
     public GridGeometry slice(final DirectPosition slicePoint) {
         ArgumentChecks.ensureNonNull("slicePoint", slicePoint);
         requireGridToCRS();
-        final GridExtent slice;
         try {
-            slice = new SubgridCalculator(this, cornerToCRS, 
slicePoint).extent;
+            final GridExtent slice = new SubgridCalculator(this, cornerToCRS, 
slicePoint).extent;
+            if (slice != extent) {
+                return new GridGeometry(this, slice, null);
+            }
         } catch (TransformException e) {
-            throw new InvalidGridGeometryException(e);
+            throw new IllegalGridGeometryException(e, "slicePoint");
         }
-        return (slice != extent) ? new GridGeometry(this, slice, null) : this;
+        return this;
     }
 
     /**
@@ -1116,7 +1113,7 @@ public class GridGeometry implements Serializable {
         } else try {
             return new GridGeometry(this, lower, upper);
         } catch (FactoryException e) {
-            throw new InvalidGridGeometryException(e);
+            throw new IllegalGridGeometryException(e, "dimensions");
         }
     }
 
diff --git 
a/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/InvalidGridGeometryException.java
 
b/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/IllegalGridGeometryException.java
similarity index 71%
rename from 
core/sis-raster/src/main/java/org/apache/sis/coverage/grid/InvalidGridGeometryException.java
rename to 
core/sis-raster/src/main/java/org/apache/sis/coverage/grid/IllegalGridGeometryException.java
index 3e25392..fcfb8be 100644
--- 
a/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/InvalidGridGeometryException.java
+++ 
b/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/IllegalGridGeometryException.java
@@ -16,6 +16,8 @@
  */
 package org.apache.sis.coverage.grid;
 
+import org.apache.sis.internal.raster.Resources;
+
 
 /**
  * Thrown when the argument specified to a method or constructor would result 
in an invalid {@link GridGeometry}.
@@ -25,7 +27,7 @@ package org.apache.sis.coverage.grid;
  * @since   1.0
  * @module
  */
-public class InvalidGridGeometryException extends IllegalArgumentException {
+public class IllegalGridGeometryException extends IllegalArgumentException {
     /**
      * Serial number for inter-operability with different versions.
      */
@@ -34,7 +36,7 @@ public class InvalidGridGeometryException extends 
IllegalArgumentException {
     /**
      * Constructs an exception with no detail message.
      */
-    public InvalidGridGeometryException() {
+    public IllegalGridGeometryException() {
     }
 
     /**
@@ -42,26 +44,27 @@ public class InvalidGridGeometryException extends 
IllegalArgumentException {
      *
      * @param  message  the detail message.
      */
-    public InvalidGridGeometryException(final String message) {
+    public IllegalGridGeometryException(final String message) {
         super(message);
     }
 
     /**
-     * Constructs an exception with the specified cause.
+     * Constructs an exception with the specified detail message and cause.
      *
-     * @param  cause  the cause for this exception.
+     * @param  message  the detail message.
+     * @param  cause    the cause for this exception.
      */
-    public InvalidGridGeometryException(final Throwable cause) {
-        super(cause);
+    public IllegalGridGeometryException(final String message, final Throwable 
cause) {
+        super(message, cause);
     }
 
     /**
-     * Constructs an exception with the specified detail message and cause.
+     * Constructs an exception with a detail message incriminating the given 
parameter.
      *
-     * @param  message  the detail message.
-     * @param  cause    the cause for this exception.
+     * @param cause      the cause of the failure to create the grid geometry.
+     * @param component  name of the parameter that caused the failure.
      */
-    public InvalidGridGeometryException(final String message, final Throwable 
cause) {
-        super(message, cause);
+    IllegalGridGeometryException(final Throwable cause, final String 
component) {
+        super(Resources.format(Resources.Keys.IllegalGridGeometryComponent_1, 
component));
     }
 }
diff --git 
a/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/IncompleteGridGeometryException.java
 
b/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/IncompleteGridGeometryException.java
index 0ea406c..84f5bbe 100644
--- 
a/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/IncompleteGridGeometryException.java
+++ 
b/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/IncompleteGridGeometryException.java
@@ -16,8 +16,6 @@
  */
 package org.apache.sis.coverage.grid;
 
-import org.apache.sis.internal.raster.Resources;
-
 
 /**
  * Thrown by {@link GridGeometry} when a grid geometry can not provide the 
requested information.
@@ -42,14 +40,6 @@ public class IncompleteGridGeometryException extends 
IllegalStateException {
     }
 
     /**
-     * Constructs an exception with a detail message from the specified error 
code.
-     * Should not be public because the SIS I18N framework is not a committed 
one.
-     */
-    IncompleteGridGeometryException(final short code) {
-        super(Resources.format(code));
-    }
-
-    /**
      * Constructs an exception with the specified detail message.
      *
      * @param  message  the detail message.
diff --git 
a/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/SubgridCalculator.java
 
b/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/SubgridCalculator.java
index 8f307ae..e4966a1 100644
--- 
a/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/SubgridCalculator.java
+++ 
b/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/SubgridCalculator.java
@@ -116,35 +116,31 @@ final class SubgridCalculator {
      * @throws TransformException if an error occurred while converting the 
envelope coordinates to grid coordinates.
      */
     SubgridCalculator(final GridGeometry grid, MathTransform cornerToCRS, 
final Envelope areaOfInterest, double[] resolution)
-            throws TransformException
+            throws TransformException, FactoryException
     {
-        try {
-            /*
-             * If the envelope CRS is different than the expected CRS, 
concatenate the envelope transformation
-             * to the 'gridToCRS' transform.  We should not transform the 
envelope here - only concatenate the
-             * transforms - because transforming envelopes twice would add 
errors.
-             */
-            final CoordinateOperation operation = 
Envelopes.findOperation(grid.envelope, areaOfInterest);
-            if (operation != null) {
-                cornerToCRS = MathTransforms.concatenate(cornerToCRS, 
operation.getMathTransform());
-            }
-            /*
-             * If the envelope dimensions does not encompass all grid 
dimensions, the envelope is probably non-invertible.
-             * We need to reduce the number of grid dimensions in the 
transform for having a one-to-one relationship.
-             */
-            final int dimension = cornerToCRS.getTargetDimensions();
-            ArgumentChecks.ensureDimensionMatches("areaOfInterest", dimension, 
areaOfInterest);
-            cornerToCRS = dropUnusedDimensions(cornerToCRS, dimension);
-        } catch (FactoryException e) {
-            throw new 
TransformException(Resources.format(Resources.Keys.CanNotMapToGridDimensions), 
e);
+        /*
+         * If the envelope CRS is different than the expected CRS, concatenate 
the envelope transformation
+         * to the 'gridToCRS' transform.  We should not transform the envelope 
here - only concatenate the
+         * transforms - because transforming envelopes twice would add errors.
+         */
+        final CoordinateOperation operation = 
Envelopes.findOperation(grid.envelope, areaOfInterest);
+        if (operation != null) {
+            cornerToCRS = MathTransforms.concatenate(cornerToCRS, 
operation.getMathTransform());
         }
         /*
+         * If the envelope dimensions does not encompass all grid dimensions, 
the envelope is probably non-invertible.
+         * We need to reduce the number of grid dimensions in the transform 
for having a one-to-one relationship.
+         */
+        int dimension = cornerToCRS.getTargetDimensions();
+        ArgumentChecks.ensureDimensionMatches("areaOfInterest", dimension, 
areaOfInterest);
+        cornerToCRS = dropUnusedDimensions(cornerToCRS, dimension);
+        /*
          * Compute the sub-extent for the given Area Of Interest (AOI), 
ignoring for now the sub-sampling.
          * If no area of interest has been specified, or if the result is 
identical to the original extent,
          * then we will keep the reference to the original GridExtent (i.e. we 
share existing instances).
          */
         extent = grid.extent;
-        final int dimension = extent.getDimension();
+        dimension = extent.getDimension();
         GeneralEnvelope indices = null;
         if (areaOfInterest != null) {
             indices = Envelopes.transform(cornerToCRS.inverse(), 
areaOfInterest);
diff --git 
a/core/sis-raster/src/main/java/org/apache/sis/internal/raster/Resources.java 
b/core/sis-raster/src/main/java/org/apache/sis/internal/raster/Resources.java
index 52edab2..51ef8eb 100644
--- 
a/core/sis-raster/src/main/java/org/apache/sis/internal/raster/Resources.java
+++ 
b/core/sis-raster/src/main/java/org/apache/sis/internal/raster/Resources.java
@@ -95,6 +95,11 @@ public final class Resources extends IndexedResourceBundle {
         public static final short IllegalGridEnvelope_3 = 8;
 
         /**
+         * Can not create a grid geometry with the given “{0}” component.
+         */
+        public static final short IllegalGridGeometryComponent_1 = 23;
+
+        /**
          * Illegal transfer function for “{0}” category.
          */
         public static final short IllegalTransferFunction_1 = 16;
diff --git 
a/core/sis-raster/src/main/java/org/apache/sis/internal/raster/Resources.properties
 
b/core/sis-raster/src/main/java/org/apache/sis/internal/raster/Resources.properties
index e8e3789..0f5531c 100644
--- 
a/core/sis-raster/src/main/java/org/apache/sis/internal/raster/Resources.properties
+++ 
b/core/sis-raster/src/main/java/org/apache/sis/internal/raster/Resources.properties
@@ -26,6 +26,7 @@ CategoryRangeOverlap_4            = The two categories 
\u201c{0}\u201d and \u201
 GridCoordinateOutsideCoverage_4   = Indices ({3}) are outside grid coverage. 
The value at dimension {0} shall be between {1} and {2} inclusive.
 IllegalCategoryRange_2            = Sample value range {1} for \u201c{0}\u201d 
category is illegal.
 IllegalGridEnvelope_3             = Illegal grid envelope [{1} \u2026 {2}] for 
dimension {0}.
+IllegalGridGeometryComponent_1    = Can not create a grid geometry with the 
given \u201c{0}\u201d component.
 IllegalTransferFunction_1         = Illegal transfer function for 
\u201c{0}\u201d category.
 IncompatibleTile_2                = The ({0}, {1}) tile has an unexpected 
size, number of bands or sample layout.
 IterationIsFinished               = Iteration is finished.
diff --git 
a/core/sis-raster/src/main/java/org/apache/sis/internal/raster/Resources_fr.properties
 
b/core/sis-raster/src/main/java/org/apache/sis/internal/raster/Resources_fr.properties
index 6b580ee..0dc3acb 100644
--- 
a/core/sis-raster/src/main/java/org/apache/sis/internal/raster/Resources_fr.properties
+++ 
b/core/sis-raster/src/main/java/org/apache/sis/internal/raster/Resources_fr.properties
@@ -31,6 +31,7 @@ CategoryRangeOverlap_4            = Les deux cat\u00e9gories 
\u00ab\u202f{0}\u20
 GridCoordinateOutsideCoverage_4   = Les indices ({3}) sont en dehors du 
domaine de la grille. La valeur \u00e0 la dimension {0} doit \u00eatre entre 
{1} et {2} inclusivement.
 IllegalCategoryRange_2            = La plage de valeurs {1} pour la 
cat\u00e9gorie \u00ab\u202f{0}\u202f\u00bb est ill\u00e9gale.
 IllegalGridEnvelope_3             = La plage d\u2019index [{1} \u2026 {2}] de 
la dimension {0} n\u2019est pas valide.
+IllegalGridGeometryComponent_1    = Ne peut pas construire une 
g\u00e9om\u00e9trie de grille avec la composante \u00ab\u202f{0}\u202f\u00bb 
donn\u00e9e.
 IllegalTransferFunction_1         = Fonction de transfert ill\u00e9gale pour 
la cat\u00e9gorie \u00ab\u202f{0}\u202f\u00bb.
 IncompatibleTile_2                = La tuile ({0}, {1}) a une taille, un 
nombre de bandes ou une disposition des valeurs inattendu.
 IterationIsFinished               = L\u2019it\u00e9ration est termin\u00e9e.
diff --git 
a/core/sis-raster/src/test/java/org/apache/sis/coverage/grid/GridGeometryTest.java
 
b/core/sis-raster/src/test/java/org/apache/sis/coverage/grid/GridGeometryTest.java
index a86d706..b692e2f 100644
--- 
a/core/sis-raster/src/test/java/org/apache/sis/coverage/grid/GridGeometryTest.java
+++ 
b/core/sis-raster/src/test/java/org/apache/sis/coverage/grid/GridGeometryTest.java
@@ -142,9 +142,11 @@ public final strictfp class GridGeometryTest extends 
TestCase {
 
     /**
      * Tests the {@link GridGeometry#GridGeometry(GridGeometry, GridExtent, 
MathTransform)} constructor.
+     *
+     * @throws TransformException if an error occurred while using the "grid 
to CRS" transform.
      */
     @Test
-    public void testFromOther() {
+    public void testFromOther() throws TransformException {
         long[]        low       = new long[] {  1,   3, 2};
         long[]        high      = new long[] {101, 203, 4};
         GridExtent    extent    = new GridExtent(null, low, high, false);
diff --git 
a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Grid.java 
b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Grid.java
index a89c8c9..cc50061 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Grid.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Grid.java
@@ -25,7 +25,6 @@ import org.opengis.util.FactoryException;
 import org.opengis.referencing.datum.PixelInCell;
 import org.opengis.referencing.operation.Matrix;
 import org.opengis.referencing.operation.MathTransform;
-import org.opengis.referencing.operation.TransformException;
 import org.opengis.referencing.operation.MathTransformFactory;
 import org.opengis.referencing.cs.CoordinateSystem;
 import org.opengis.referencing.crs.SingleCRS;
@@ -38,6 +37,7 @@ import 
org.apache.sis.referencing.operation.builder.LocalizationGridBuilder;
 import org.apache.sis.referencing.CRS;
 import org.apache.sis.coverage.grid.GridExtent;
 import org.apache.sis.coverage.grid.GridGeometry;
+import org.apache.sis.coverage.grid.IllegalGridGeometryException;
 import org.apache.sis.storage.DataStoreException;
 import org.apache.sis.util.NullArgumentException;
 import org.apache.sis.math.Vector;
@@ -397,7 +397,7 @@ findFree:       for (int srcDim : axis.sourceDimensions) {
                 }
             }
             geometry = new GridGeometry(getExtent(axes), anchor, gridToCRS, 
crs);
-        } catch (FactoryException ex) {
+        } catch (FactoryException | IllegalGridGeometryException ex) {
             canNotCreate(decoder, "getGridGeometry", 
Resources.Keys.CanNotCreateGridGeometry_3, ex);
         }
         return geometry;

Reply via email to