This is an automated email from the ASF dual-hosted git repository. asf-gitbox-commits pushed a commit to branch geoapi-4.0 in repository https://gitbox.apache.org/repos/asf/sis.git
commit 0538a8c51fc1a1d463b9d0469b213f4d0b2ce40a Author: Martin Desruisseaux <[email protected]> AuthorDate: Tue Oct 20 00:32:57 2026 +0200 Tries to be a little bit more specific about the cause of `TransformException`, especially when the exception happens at transform creation time. --- .../org/apache/sis/coverage/RegionOfInterest.java | 8 ++- .../apache/sis/coverage/grid/DefaultEvaluator.java | 3 +- .../apache/sis/coverage/grid/DomainLinearizer.java | 3 +- .../sis/coverage/grid/GridCoverageProcessor.java | 3 +- .../org/apache/sis/coverage/grid/GridGeometry.java | 5 +- .../sis/geometry/wrapper/GeometryWrapper.java | 7 +-- .../apache/sis/geometry/wrapper/jts/Wrapper.java | 7 +-- .../referencing/gazetteer/GazetteerException.java | 3 +- .../main/org/apache/sis/geometry/Envelopes.java | 7 ++- .../apache/sis/geometry/WraparoundAdjustment.java | 5 +- .../referencing/internal/PositionTransformer.java | 7 ++- .../apache/sis/referencing/internal/Resources.java | 5 ++ .../sis/referencing/internal/Resources.properties | 1 + .../referencing/internal/Resources_fr.properties | 1 + .../referencing/internal/ServicesForMetadata.java | 3 +- .../internal/shared/ExtentSelector.java | 2 +- .../operation/CoordinateOperationFinder.java | 8 +-- .../operation/DefaultConcatenatedOperation.java | 10 ++-- .../DefaultCoordinateOperationFactory.java | 35 ++++++----- .../operation/TransformedCoordinateSet.java | 7 ++- .../operation/projection/ProjectionException.java | 3 +- .../transform/TransformFactoryException.java | 68 ++++++++++++++++++++++ .../operation/transform/package-info.java | 2 +- .../DefaultCoordinateOperationFactoryTest.java | 3 +- .../apache/sis/storage/tiling/TileReadEvent.java | 3 +- .../org/apache/sis/geometries/adapter/Wrapper.java | 3 +- .../apache/sis/referencing/dggs/s2/S2Coder.java | 3 +- .../org/apache/sis/referencing/dggs/s2/S2Dgg.java | 3 +- .../storage/dggs/DiscreteGlobalGridGeometry.java | 3 +- 29 files changed, 156 insertions(+), 65 deletions(-) diff --git a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/RegionOfInterest.java b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/RegionOfInterest.java index 5ff42ce19e..e583da3d1d 100644 --- a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/RegionOfInterest.java +++ b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/RegionOfInterest.java @@ -27,8 +27,10 @@ import org.opengis.referencing.operation.MathTransform2D; import org.opengis.referencing.operation.TransformException; import org.apache.sis.referencing.CRS; import org.apache.sis.referencing.operation.transform.MathTransforms; +import org.apache.sis.referencing.operation.transform.TransformFactoryException; import org.apache.sis.coverage.grid.GridGeometry; import org.apache.sis.coverage.grid.PixelInCell; +import org.apache.sis.feature.internal.Resources; import org.apache.sis.util.LenientComparable; import org.apache.sis.util.ArgumentChecks; import org.apache.sis.util.ComparisonMode; @@ -110,8 +112,10 @@ public class RegionOfInterest implements LenientComparable, Serializable { tr = MathTransforms.concatenate(op.getMathTransform(), tr); } crsToGrid = MathTransforms.bidimensional(tr); - } catch (IllegalArgumentException | FactoryException e) { - throw new TransformException(e); + } catch (FactoryException e) { + throw new TransformFactoryException(e); + } catch (IllegalArgumentException e) { // Generalization of MismatchedDimensionException. + throw new TransformException(Resources.format(Resources.Keys.IllegalGridGeometryComponent_1, "gridToCRS"), e); } return crsToGrid.createTransformedShape(geometry); } diff --git a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/DefaultEvaluator.java b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/DefaultEvaluator.java index d558111d14..8fef954d25 100644 --- a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/DefaultEvaluator.java +++ b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/DefaultEvaluator.java @@ -42,6 +42,7 @@ import org.apache.sis.referencing.operation.matrix.Matrices; import org.apache.sis.referencing.operation.matrix.MatrixSIS; import org.apache.sis.referencing.operation.transform.MathTransforms; import org.apache.sis.referencing.operation.transform.TransformSeparator; +import org.apache.sis.referencing.operation.transform.TransformFactoryException; import org.apache.sis.geometry.CoordinateFormat; import org.apache.sis.feature.internal.Resources; import org.apache.sis.util.ArraysExt; @@ -490,7 +491,7 @@ abstract class DefaultEvaluator implements GridCoverage.Evaluator { final int dimension = inputToGrid.getTargetDimensions(); return new FractionalGridCoordinates(ArraysExt.resize(gridCoords, dimension)); } catch (FactoryException e) { - throw new TransformException(e.getMessage(), e); + throw new TransformFactoryException(e); } } diff --git a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/DomainLinearizer.java b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/DomainLinearizer.java index a2efd3871d..ed88e5ae6e 100644 --- a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/DomainLinearizer.java +++ b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/DomainLinearizer.java @@ -23,6 +23,7 @@ import org.opengis.referencing.operation.TransformException; import org.apache.sis.referencing.operation.builder.LinearTransformBuilder; import org.apache.sis.referencing.operation.transform.LinearTransform; import org.apache.sis.referencing.operation.transform.MathTransforms; +import org.apache.sis.referencing.operation.transform.TransformFactoryException; import org.apache.sis.geometry.GeneralEnvelope; import org.apache.sis.geometry.Envelopes; import org.apache.sis.util.ArgumentChecks; @@ -193,7 +194,7 @@ public class DomainLinearizer { if (cause instanceof TransformException) { throw (TransformException) cause; } - throw new TransformException(e); + throw new TransformFactoryException(e); } return gg; } diff --git a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/GridCoverageProcessor.java b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/GridCoverageProcessor.java index 4bf9c54e72..6ae59780f6 100644 --- a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/GridCoverageProcessor.java +++ b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/GridCoverageProcessor.java @@ -51,6 +51,7 @@ import org.apache.sis.coverage.internal.shared.BandAggregateArgument; import org.apache.sis.referencing.CommonCRS; import org.apache.sis.referencing.crs.DefaultTemporalCRS; import org.apache.sis.referencing.operation.transform.MathTransforms; +import org.apache.sis.referencing.operation.transform.TransformFactoryException; import org.apache.sis.util.ArgumentChecks; import org.apache.sis.util.logging.Logging; import org.apache.sis.util.collection.WeakHashSet; @@ -624,7 +625,7 @@ public class GridCoverageProcessor implements Cloneable { throw e; } } catch (FactoryException e) { - throw new TransformException(e.getMessage(), e); + throw new TransformFactoryException(e); } return resampled.forConvertedValues(isConverted); } diff --git a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/GridGeometry.java b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/GridGeometry.java index 047f91b300..5d0e099927 100644 --- a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/GridGeometry.java +++ b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/GridGeometry.java @@ -60,6 +60,7 @@ import org.apache.sis.referencing.operation.matrix.MatrixSIS; import org.apache.sis.referencing.operation.transform.MathTransforms; import org.apache.sis.referencing.operation.transform.LinearTransform; import org.apache.sis.referencing.operation.transform.PassThroughTransform; +import org.apache.sis.referencing.operation.transform.TransformFactoryException; import org.apache.sis.referencing.factory.InvalidGeodeticParameterException; import org.apache.sis.referencing.internal.shared.ExtendedPrecisionMatrix; import org.apache.sis.referencing.internal.shared.DirectPositionView; @@ -1131,7 +1132,7 @@ public class GridGeometry implements LenientComparable, Serializable { } return env; } catch (FactoryException e) { - throw new TransformException(e); + throw new TransformFactoryException(e); } throw incomplete(bitmask, errorKey); } @@ -1994,7 +1995,7 @@ public class GridGeometry implements LenientComparable, Serializable { try { tr = finder.inverse(); } catch (FactoryException e) { - throw new TransformException(e); + throw new TransformFactoryException(e); } return MathTransforms.concatenate(getGridToCRS(anchor), tr); } diff --git a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/geometry/wrapper/GeometryWrapper.java b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/geometry/wrapper/GeometryWrapper.java index 9a871893de..1c02ea6a1b 100644 --- a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/geometry/wrapper/GeometryWrapper.java +++ b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/geometry/wrapper/GeometryWrapper.java @@ -34,6 +34,7 @@ import org.apache.sis.geometry.GeneralEnvelope; import org.apache.sis.filter.sqlmm.SQLMM; import org.apache.sis.referencing.CRS; import org.apache.sis.referencing.operation.transform.MathTransforms; +import org.apache.sis.referencing.operation.transform.TransformFactoryException; import org.apache.sis.referencing.internal.shared.ReferencingUtilities; import org.apache.sis.util.ArgumentChecks; import org.apache.sis.util.Classes; @@ -565,11 +566,7 @@ public abstract class GeometryWrapper extends AbstractGeometry implements Geomet try { return transform(CRS.findOperation(crs, targetCRS, null), false); } catch (FactoryException e) { - /* - * We wrap that exception because `Geometry.transform(…)` does not declare `FactoryException`. - * We may revisit in a future version if `Geometry.transform(…)` method declaration is updated. - */ - throw new TransformException(e); + throw new TransformFactoryException(e); } } diff --git a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/geometry/wrapper/jts/Wrapper.java b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/geometry/wrapper/jts/Wrapper.java index 4f77c2e54d..bae9ca35f0 100644 --- a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/geometry/wrapper/jts/Wrapper.java +++ b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/geometry/wrapper/jts/Wrapper.java @@ -47,6 +47,7 @@ import org.opengis.referencing.operation.CoordinateOperation; import org.opengis.referencing.operation.MathTransform; import org.opengis.referencing.operation.TransformException; import org.apache.sis.referencing.CRS; +import org.apache.sis.referencing.operation.transform.TransformFactoryException; import org.apache.sis.geometry.DirectPosition2D; import org.apache.sis.geometry.GeneralDirectPosition; import org.apache.sis.geometry.GeneralEnvelope; @@ -733,11 +734,7 @@ add: for (Geometry next = geometry;;) { try { return rewrap(JTS.transform(geometry, targetCRS)); } catch (FactoryException e) { - /* - * We wrap that exception because `Geometry.transform(…)` does not declare `FactoryException`. - * We may revisit in a future version if `Geometry.transform(…)` method declaration is updated. - */ - throw new TransformException(e); + throw new TransformFactoryException(e); } } diff --git a/endorsed/src/org.apache.sis.referencing.gazetteer/main/org/apache/sis/referencing/gazetteer/GazetteerException.java b/endorsed/src/org.apache.sis.referencing.gazetteer/main/org/apache/sis/referencing/gazetteer/GazetteerException.java index 0781061f68..82d82bba6a 100644 --- a/endorsed/src/org.apache.sis.referencing.gazetteer/main/org/apache/sis/referencing/gazetteer/GazetteerException.java +++ b/endorsed/src/org.apache.sis.referencing.gazetteer/main/org/apache/sis/referencing/gazetteer/GazetteerException.java @@ -54,8 +54,7 @@ public class GazetteerException extends TransformException { * @param cause the cause, or {@code null} if none. */ public GazetteerException(final Throwable cause) { - // Reproduce the behavior of standard Throwable(Throwable) constructor. - super((cause != null) ? cause.toString() : null, cause); + super(cause); } /** diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/geometry/Envelopes.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/geometry/Envelopes.java index 17d9fa6bd6..47547f42c1 100644 --- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/geometry/Envelopes.java +++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/geometry/Envelopes.java @@ -50,6 +50,7 @@ import org.apache.sis.referencing.operation.AbstractCoordinateOperation; import org.apache.sis.referencing.operation.transform.AbstractMathTransform; import org.apache.sis.referencing.operation.transform.WraparoundTransform; import org.apache.sis.referencing.operation.transform.MathTransforms; +import org.apache.sis.referencing.operation.transform.TransformFactoryException; import org.apache.sis.referencing.internal.shared.CoordinateOperations; import org.apache.sis.referencing.internal.shared.DirectPositionView; import org.apache.sis.referencing.internal.shared.TemporalAccessor; @@ -337,8 +338,8 @@ public final class Envelopes { final CoordinateOperation operation; try { operation = CRS.findOperation(sourceCRS, targetCRS, null); - } catch (FactoryException exception) { - throw new TransformException(Errors.format(Errors.Keys.CanNotTransformEnvelope), exception); + } catch (FactoryException e) { + throw new TransformFactoryException(Errors.format(Errors.Keys.CanNotTransformEnvelope), e); } envelope = transform(operation, envelope); } @@ -625,7 +626,7 @@ nextPoint: for (int pointIndex = 0;;) { // Break condition at th new DefaultCoordinateMetadata(sourceCRS, null), context).getMathTransform(); } catch (FactoryException e) { - throw new TransformException(Errors.format(Errors.Keys.CanNotTransformEnvelope), e); + throw new TransformFactoryException(Errors.format(Errors.Keys.CanNotTransformEnvelope), e); } if (!prefix.isIdentity()) { mt = MathTransforms.concatenate(prefix, mt); diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/geometry/WraparoundAdjustment.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/geometry/WraparoundAdjustment.java index 51b7430467..c27ee717a3 100644 --- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/geometry/WraparoundAdjustment.java +++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/geometry/WraparoundAdjustment.java @@ -27,9 +27,10 @@ import org.opengis.referencing.operation.CoordinateOperation; import org.opengis.metadata.extent.GeographicBoundingBox; import org.apache.sis.referencing.CRS; import org.apache.sis.referencing.operation.transform.MathTransforms; +import org.apache.sis.referencing.operation.transform.TransformFactoryException; +import org.apache.sis.referencing.internal.shared.WraparoundAxesFinder; import org.apache.sis.math.MathFunctions; import org.apache.sis.metadata.internal.shared.ReferencingServices; -import org.apache.sis.referencing.internal.shared.WraparoundAxesFinder; import org.apache.sis.util.logging.Logging; @@ -191,7 +192,7 @@ public class WraparoundAdjustment { try { return CRS.findOperation(source, target, geographicDomain); } catch (FactoryException e) { - throw new TransformException(e); + throw new TransformFactoryException(e); } } diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/internal/PositionTransformer.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/internal/PositionTransformer.java index 9fc2ac6a7c..e7da88e555 100644 --- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/internal/PositionTransformer.java +++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/internal/PositionTransformer.java @@ -28,6 +28,7 @@ import org.opengis.referencing.operation.TransformException; import org.apache.sis.referencing.CRS; import org.apache.sis.referencing.MultiRegisterOperations; import org.apache.sis.referencing.operation.transform.MathTransforms; +import org.apache.sis.referencing.operation.transform.TransformFactoryException; import org.apache.sis.geometry.GeneralDirectPosition; // Specific to the geoapi-3.1 and geoapi-4.0 branches: @@ -162,8 +163,10 @@ public final class PositionTransformer extends GeneralDirectPosition { final CoordinateOperation operation; try { operation = factory.findCoordinateOperations(crs, targetCRS).iterator().next(); - } catch (FactoryException | NoSuchElementException exception) { - throw new TransformException(exception.getLocalizedMessage(), exception); + } catch (NoSuchElementException e) { + throw new TransformException(Resources.format(Resources.Keys.CanNotCreateTransform), e); + } catch (FactoryException e) { + throw new TransformFactoryException(e); } /* * Note: `lastCRS` should be set last, when we are sure that all other fields diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/internal/Resources.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/internal/Resources.java index 5a612d7d0b..01a6985b81 100644 --- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/internal/Resources.java +++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/internal/Resources.java @@ -115,6 +115,11 @@ public class Resources extends IndexedResourceBundle { */ public static final short CanNotCreateObjectAsInstanceOf_2 = 4; + /** + * Cannot prepare a plan for performing the coordinate operation. + */ + public static final short CanNotCreateTransform = 110; + /** * Cannot find a coordinate reference system common to all given envelopes. */ diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/internal/Resources.properties b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/internal/Resources.properties index 188e354248..46be9f59d0 100644 --- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/internal/Resources.properties +++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/internal/Resources.properties @@ -55,6 +55,7 @@ CanNotComputeDerivative = Cannot compute the coordinate operation deri CanNotConcatenateTransforms_2 = Cannot concatenate transforms \u201c{0}\u201d and \u201c{1}\u201d. CanNotConvertCoordinates_2 = Cannot convert a point {0,choice,0#from|1#to} coordinate reference system \u201c{1}\u201d. CanNotCreateObjectAsInstanceOf_2 = Cannot create an object of type \u201c{1}\u201d as an instance of class \u2018{0}\u2019. +CanNotCreateTransform = Cannot prepare a plan for performing the coordinate operation. CanNotFindCommonCRS = Cannot find a coordinate reference system common to all given envelopes. CanNotInferGridSizeFromValues_1 = Cannot infer a grid size from the given values in {0} range. CanNotInstantiateGeodeticObject_1 = Cannot instantiate geodetic object for \u201c{0}\u201d. diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/internal/Resources_fr.properties b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/internal/Resources_fr.properties index 751d994bc7..6da8a04405 100644 --- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/internal/Resources_fr.properties +++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/internal/Resources_fr.properties @@ -60,6 +60,7 @@ CanNotComputeDerivative = La d\u00e9riv\u00e9 de l\u2019op\u00e9ration CanNotConcatenateTransforms_2 = Les transformations \u00ab\u202f{0}\u202f\u00bb et \u00ab\u202f{1}\u202f\u00bb ne peuvent pas \u00eatre combin\u00e9es. CanNotConvertCoordinates_2 = Ne peut pas convertir un point {0,choice,0#\u00e0 partir du|1#vers le} syst\u00e8me de r\u00e9f\u00e9rence des coordonn\u00e9es \u00ab\u202f{1}\u202f\u00bb. CanNotCreateObjectAsInstanceOf_2 = Ne peut pas cr\u00e9er un objet du type \u00ab\u202f{1}\u202f\u00bb comme une instance de la classe \u2018{0}\u2019. +CanNotCreateTransform = Ne peut pas pr\u00e9parer un plan pour effectuer l\u2019op\u00e9ration sur les coordonn\u00e9es. CanNotFindCommonCRS = Ne peut pas trouver un syst\u00e8me de r\u00e9f\u00e9rence des coordonn\u00e9es commun pour toutes les enveloppes donn\u00e9es. CanNotInferGridSizeFromValues_1 = Ne peut pas inf\u00e9rer une taille de grille \u00e0 partir des valeurs donn\u00e9es dans la plage {0}. CanNotInstantiateGeodeticObject_1 = Ne peut pas cr\u00e9er l\u2019objet g\u00e9od\u00e9tique pour \u00ab\u202f{0}\u202f\u00bb. diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/internal/ServicesForMetadata.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/internal/ServicesForMetadata.java index 3ea58e9447..5c8ba22051 100644 --- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/internal/ServicesForMetadata.java +++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/internal/ServicesForMetadata.java @@ -52,6 +52,7 @@ import org.apache.sis.referencing.IdentifiedObjects; import org.apache.sis.referencing.internal.shared.AxisDirections; import org.apache.sis.referencing.internal.shared.TemporalAccessor; import org.apache.sis.referencing.internal.shared.ReferencingUtilities; +import org.apache.sis.referencing.operation.transform.TransformFactoryException; import org.apache.sis.parameter.DefaultParameterDescriptor; import org.apache.sis.metadata.iso.extent.DefaultExtent; import org.apache.sis.metadata.iso.extent.DefaultVerticalExtent; @@ -135,7 +136,7 @@ public final class ServicesForMetadata extends ReferencingServices { Logging.recoverableException(getLogger(Modules.REFERENCING), Envelopes.class, findOpCaller, e); return null; } - throw new TransformException(Resources.format(Resources.Keys.CanNotTransformEnvelopeToGeodetic), e); + throw new TransformFactoryException(Resources.format(Resources.Keys.CanNotTransformEnvelopeToGeodetic), e); } envelope = Envelopes.transform(operation, envelope); } diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/internal/shared/ExtentSelector.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/internal/shared/ExtentSelector.java index 1d8dfdcc99..63037a6eed 100644 --- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/internal/shared/ExtentSelector.java +++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/internal/shared/ExtentSelector.java @@ -201,7 +201,7 @@ public final class ExtentSelector<T> { */ public ExtentSelector(final Extent domain) { if (!setExtentOfInterest(domain, null, null)) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException(Errors.format(Errors.Keys.EmptyArgument_1, "domain")); } } diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/CoordinateOperationFinder.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/CoordinateOperationFinder.java index c05a7acdba..68dab41148 100644 --- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/CoordinateOperationFinder.java +++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/CoordinateOperationFinder.java @@ -504,10 +504,6 @@ public class CoordinateOperationFinder extends CoordinateOperationRegistry { * coordinate system type (Ellipsoidal ↔ Cartesian ↔ Spherical), axis swapping and unit conversions. */ Identifier typeOfChange; - final Matrix datumShift; - final MathTransform transform; - ParameterValueGroup parameters; - final Optional<OperationMethod> method; final Optional<GeodeticDatum> finalDatum; final boolean sameDatumOrEnsemble; if (Utilities.equalsIgnoreMetadata(sourceDatum, targetDatum)) { @@ -520,6 +516,10 @@ public class CoordinateOperationFinder extends CoordinateOperationRegistry { sameDatumOrEnsemble = finalDatum.isPresent(); typeOfChange = sameDatumOrEnsemble ? SAME_DATUM_ENSEMBLE : UNSPECIFIED_DATUM_CHANGE; } + final Matrix datumShift; + final MathTransform transform; + ParameterValueGroup parameters; + final Optional<OperationMethod> method; if (sameDatumOrEnsemble) { /* * Coordinate system change (including change in the number of dimensions) without datum shift. diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/DefaultConcatenatedOperation.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/DefaultConcatenatedOperation.java index 5dc434130b..2e882fecf1 100644 --- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/DefaultConcatenatedOperation.java +++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/DefaultConcatenatedOperation.java @@ -341,10 +341,10 @@ final class DefaultConcatenatedOperation extends AbstractCoordinateOperation imp * Verifies if a step of a concatenated operation can be chained after the previous step. * * @param properties user-specified properties (for the locale of error message), or {@code null} if none. - * @param step index of the operation step, used only in case an exception it thrown. - * @param previous Target CRS of the previous step. - * @param source Source CRS of the current step. - * @param target Target CRS of the current step, or {@code null} if none. + * @param step zero-based index of the operation step, used only in case an exception it thrown. + * @param previous target CRS of the previous step. + * @param source source CRS of the current step. + * @param target target CRS of the current step, or {@code null} if none. * @return whether the math transform needs to be inverted. * @throws FactoryException if the current operation cannot be chained after the previous operation. */ @@ -364,7 +364,7 @@ final class DefaultConcatenatedOperation extends AbstractCoordinateOperation imp Resources resources = Resources.forProperties(properties); Locale locale = resources.getLocale(); throw new InvalidGeodeticParameterException(resources.getString( - Resources.Keys.MismatchedSourceTargetCRS_3, step, + Resources.Keys.MismatchedSourceTargetCRS_3, step + 1, IdentifiedObjects.getDisplayName(previous, locale), IdentifiedObjects.getDisplayName(source, locale))); } diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/DefaultCoordinateOperationFactory.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/DefaultCoordinateOperationFactory.java index 1e05c2e756..31742a544d 100644 --- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/DefaultCoordinateOperationFactory.java +++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/DefaultCoordinateOperationFactory.java @@ -46,7 +46,6 @@ import org.apache.sis.referencing.internal.shared.CoordinateOperations; import org.apache.sis.referencing.internal.shared.ReferencingFactoryContainer; import org.apache.sis.util.ArgumentChecks; import org.apache.sis.util.Classes; -import org.apache.sis.util.Debug; import org.apache.sis.util.LenientComparable; import org.apache.sis.util.internal.shared.Constants; import org.apache.sis.util.collection.WeakHashSet; @@ -80,17 +79,10 @@ import org.apache.sis.util.resources.Errors; * This class is safe for multi-thread usage if all referenced factories are thread-safe. * * @author Martin Desruisseaux (IRD, Geomatys) - * @version 1.7 + * @version 1.8 * @since 0.6 */ public class DefaultCoordinateOperationFactory extends AbstractFactory implements CoordinateOperationFactory { - /** - * Whether this class is allowed to use the EPSG authority factory for searching coordinate operation paths. - * This flag should always be {@code true}, except temporarily for testing purposes. - */ - @Debug - static final boolean USE_EPSG_FACTORY = true; - /** * The default properties, or an empty map if none. This map shall be immutable * in order to allow usage without synchronization in multi-thread context. @@ -677,7 +669,13 @@ next: for (SingleCRS component : CRS.getSingleComponents(targetCRS)) { op = handler.peek(); if (op == null) { final CoordinateOperationFinder finder = createOperationFinder(getFactorySIS(), context); - op = finder.createOperation(sourceCRS, targetCRS); + try { + op = finder.createOperation(sourceCRS, targetCRS); + } catch (InvalidGeodeticParameterException e) { + // Exceptions that may be caused by invalid (source, target) pair. + // Maintenance note: keep the exception list consistent with `createOperations(…)` + throw new OperationNotFoundException(finder.notFoundMessage(sourceCRS, targetCRS), e); + } if (context != null) { resultWasContextSensitive = context.resultWasContextSensitive(); } @@ -732,18 +730,23 @@ next: for (SingleCRS component : CRS.getSingleComponents(targetCRS)) { final CoordinateOperationContext context) throws OperationNotFoundException, FactoryException { - return createOperationFinder(getFactorySIS(), context).createOperations(sourceCRS, targetCRS); + final CoordinateOperationFinder finder = createOperationFinder(getFactorySIS(), context); + try { + return finder.createOperations(sourceCRS, targetCRS); + } catch (InvalidGeodeticParameterException e) { + // Exceptions that may be caused by invalid (source, target) pair. + // Maintenance note: keep the exception list consistent with `createOperation(…)` + throw new OperationNotFoundException(finder.notFoundMessage(sourceCRS, targetCRS), e); + } } /** * Returns the Apache <abbr>SIS</abbr> implementation of the <abbr>EPSG</abbr> factory, or {@code null} if none. */ private static CoordinateOperationAuthorityFactory getFactorySIS() throws FactoryException { - if (USE_EPSG_FACTORY) { - AuthorityFactory registry = CRS.getAuthorityFactory(Constants.EPSG); - if (registry instanceof CoordinateOperationAuthorityFactory) { - return (CoordinateOperationAuthorityFactory) registry; - } + AuthorityFactory registry = CRS.getAuthorityFactory(Constants.EPSG); + if (registry instanceof CoordinateOperationAuthorityFactory) { + return (CoordinateOperationAuthorityFactory) registry; } return null; } diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/TransformedCoordinateSet.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/TransformedCoordinateSet.java index eca20504d4..5d0d891376 100644 --- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/TransformedCoordinateSet.java +++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/TransformedCoordinateSet.java @@ -28,6 +28,7 @@ import org.opengis.referencing.operation.TransformException; import org.apache.sis.referencing.CRS; import org.apache.sis.referencing.internal.Resources; import org.apache.sis.referencing.operation.transform.MathTransforms; +import org.apache.sis.referencing.operation.transform.TransformFactoryException; import org.apache.sis.util.collection.BackingStoreException; import org.apache.sis.coordinate.DefaultCoordinateMetadata; import org.apache.sis.coordinate.AbstractCoordinateSet; @@ -85,8 +86,10 @@ final class TransformedCoordinateSet extends AbstractCoordinateSet implements Un final var context = CoordinateOperationContext.fromBoundingBox(CRS.getGeographicBoundingBox(op)); final var step = new DefaultCoordinateMetadata(op.getSourceCRS(), op.getSourceEpoch().orElse(null)); transform = MathTransforms.concatenate(CRS.findOperation(metadata, step, context).getMathTransform(), transform); - } catch (FactoryException | MismatchedDimensionException e) { - throw new TransformException(e.getMessage(), e); + } catch (MismatchedDimensionException e) { + throw new TransformException(Resources.format(Resources.Keys.CanNotCreateTransform), e); + } catch (FactoryException e) { + throw new TransformFactoryException(e); } this.transform = transform; this.data = data; diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/projection/ProjectionException.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/projection/ProjectionException.java index d8b45185a9..54ebc1239e 100644 --- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/projection/ProjectionException.java +++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/projection/ProjectionException.java @@ -69,8 +69,7 @@ public class ProjectionException extends TransformException { * @param cause the cause, or {@code null} if none. */ public ProjectionException(final Throwable cause) { - // Reproduce the behavior of standard Throwable(Throwable) constructor. - super((cause != null) ? cause.toString() : null, cause); + super(cause); } /** diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/transform/TransformFactoryException.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/transform/TransformFactoryException.java new file mode 100644 index 0000000000..ce740a4cef --- /dev/null +++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/transform/TransformFactoryException.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.sis.referencing.operation.transform; + +import java.util.Objects; +import org.opengis.util.FactoryException; +import org.opengis.referencing.operation.TransformException; +import org.apache.sis.referencing.internal.Resources; + + +/** + * Thrown when a coordinate operation cannot be executed because its {@code MathTransform} cannot be created. + * This {@code TransformException} always has a {@link FactoryException} as its cause. + * + * @author Martin Desruisseaux (Geomatys) + * @version 1.8 + * @since 1.8 + */ +public class TransformFactoryException extends TransformException { + /** + * For cross-version compatibility. + */ + private static final long serialVersionUID = 3075278492210160308L; + + /** + * Creates a new exception with the given cause. + * This constructor provides a default message. + * + * @param cause the cause (cannot be {@code null}). + */ + public TransformFactoryException(FactoryException cause) { + this(Resources.format(Resources.Keys.CanNotCreateTransform), cause); + } + + /** + * Constructs a new exception with the specified detail message and cause. + * + * @param message the details message, or {@code null} if none. + * @param cause the cause (cannot be {@code null}). + */ + public TransformFactoryException(String message, FactoryException cause) { + super(message, Objects.requireNonNull(cause)); + } + + /** + * Returns the cause of this exception. + * + * @return the factory exception which is the cause of this exception. + */ + @Override + public FactoryException getCause() { + return (FactoryException) super.getCause(); + } +} diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/transform/package-info.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/transform/package-info.java index 23c92906b8..ab8dadcf18 100644 --- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/transform/package-info.java +++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/transform/package-info.java @@ -61,7 +61,7 @@ * * @author Martin Desruisseaux (IRD, Geomatys) * @author Adrian Custer (Geomatys) - * @version 1.7 + * @version 1.8 * @since 0.5 */ package org.apache.sis.referencing.operation.transform; diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/DefaultCoordinateOperationFactoryTest.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/DefaultCoordinateOperationFactoryTest.java index 3b637f77a1..34dfb59cdf 100644 --- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/DefaultCoordinateOperationFactoryTest.java +++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/DefaultCoordinateOperationFactoryTest.java @@ -137,8 +137,7 @@ public final class DefaultCoordinateOperationFactoryTest extends MathTransformTe * Returns {@code true} if {@link #factory} is expected to use the EPSG factory. */ private static boolean isUsingEpsgFactory() throws FactoryException { - return DefaultCoordinateOperationFactory.USE_EPSG_FACTORY && - CRS.getAuthorityFactory(Constants.EPSG) instanceof CoordinateOperationAuthorityFactory; + return CRS.getAuthorityFactory(Constants.EPSG) instanceof CoordinateOperationAuthorityFactory; } /** diff --git a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/tiling/TileReadEvent.java b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/tiling/TileReadEvent.java index b72132945f..eca668fca8 100644 --- a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/tiling/TileReadEvent.java +++ b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/tiling/TileReadEvent.java @@ -29,6 +29,7 @@ import org.opengis.referencing.operation.CoordinateOperation; import org.opengis.referencing.crs.CoordinateReferenceSystem; import org.apache.sis.referencing.CRS; import org.apache.sis.referencing.operation.transform.MathTransforms; +import org.apache.sis.referencing.operation.transform.TransformFactoryException; import org.apache.sis.storage.Resource; import org.apache.sis.storage.event.StoreEvent; import org.apache.sis.coverage.grid.GridExtent; @@ -156,7 +157,7 @@ public final class TileReadEvent extends StoreEvent { imageToObjective = MathTransforms.bidimensional(tr); this.crsToObjective = crsToObjective; // Store only after the rest was successful. } catch (FactoryException e) { - throw new TransformException(e); + throw new TransformFactoryException(e); } return imageToObjective; } diff --git a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/adapter/Wrapper.java b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/adapter/Wrapper.java index 10b6f46a93..b73631a02b 100644 --- a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/adapter/Wrapper.java +++ b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/adapter/Wrapper.java @@ -61,6 +61,7 @@ import org.apache.sis.measure.Quantities; import org.apache.sis.measure.Units; import org.apache.sis.referencing.CRS; import org.apache.sis.referencing.operation.transform.MathTransforms; +import org.apache.sis.referencing.operation.transform.TransformFactoryException; import org.apache.sis.util.ArgumentChecks; import org.apache.sis.util.Debug; import org.apache.sis.util.UnconvertibleObjectException; @@ -676,7 +677,7 @@ add: for (Geometry next = geometry;;) { try { return transform(CRS.findOperation(crs, targetCRS, null), false); } catch (FactoryException e) { - throw new TransformException(e); + throw new TransformFactoryException(e); } } diff --git a/incubator/src/org.apache.sis.referencing.dggs/main/org/apache/sis/referencing/dggs/s2/S2Coder.java b/incubator/src/org.apache.sis.referencing.dggs/main/org/apache/sis/referencing/dggs/s2/S2Coder.java index c3756f2c33..be7efa536d 100644 --- a/incubator/src/org.apache.sis.referencing.dggs/main/org/apache/sis/referencing/dggs/s2/S2Coder.java +++ b/incubator/src/org.apache.sis.referencing.dggs/main/org/apache/sis/referencing/dggs/s2/S2Coder.java @@ -26,6 +26,7 @@ import org.opengis.referencing.operation.TransformException; import org.opengis.util.FactoryException; import org.apache.sis.referencing.CRS; import org.apache.sis.referencing.dggs.DiscreteGlobalGridReferenceSystem; +import org.apache.sis.referencing.operation.transform.TransformFactoryException; import org.apache.sis.util.Utilities; @@ -74,7 +75,7 @@ final class S2Coder extends DiscreteGlobalGridReferenceSystem.Coder{ trs = CRS.findOperation(dpcrs, baseCrs, null).getMathTransform(); dp = trs.transform(dp, null); } catch (FactoryException ex) { - throw new TransformException(ex.getMessage(), ex); + throw new TransformFactoryException(ex); } } S2CellId cid = S2CellId.fromLatLng(S2LatLng.fromDegrees(dp.getCoordinate(1), dp.getCoordinate(0))); diff --git a/incubator/src/org.apache.sis.referencing.dggs/main/org/apache/sis/referencing/dggs/s2/S2Dgg.java b/incubator/src/org.apache.sis.referencing.dggs/main/org/apache/sis/referencing/dggs/s2/S2Dgg.java index 55aa96ccbd..fbc7886a28 100644 --- a/incubator/src/org.apache.sis.referencing.dggs/main/org/apache/sis/referencing/dggs/s2/S2Dgg.java +++ b/incubator/src/org.apache.sis.referencing.dggs/main/org/apache/sis/referencing/dggs/s2/S2Dgg.java @@ -35,6 +35,7 @@ import org.apache.sis.referencing.CRS; import org.apache.sis.util.Utilities; import org.apache.sis.referencing.dggs.Zone; import org.apache.sis.referencing.dggs.internal.shared.AbstractDiscreteGlobalGrid; +import org.apache.sis.referencing.operation.transform.TransformFactoryException; import org.apache.sis.storage.dggs.DiscreteGlobalGridSystems; @@ -72,7 +73,7 @@ final class S2Dgg extends AbstractDiscreteGlobalGrid<S2Dggh> { trs = CRS.findOperation(dpcrs, baseCrs, null).getMathTransform(); dp = trs.transform(dp, null); } catch (FactoryException ex) { - throw new TransformException(ex.getMessage(), ex); + throw new TransformFactoryException(ex); } } S2CellId cid = S2CellId.fromLatLng(S2LatLng.fromDegrees(dp.getCoordinate(1), dp.getCoordinate(0))); diff --git a/incubator/src/org.apache.sis.referencing.dggs/main/org/apache/sis/storage/dggs/DiscreteGlobalGridGeometry.java b/incubator/src/org.apache.sis.referencing.dggs/main/org/apache/sis/storage/dggs/DiscreteGlobalGridGeometry.java index 62585c0d6d..e79400d883 100644 --- a/incubator/src/org.apache.sis.referencing.dggs/main/org/apache/sis/storage/dggs/DiscreteGlobalGridGeometry.java +++ b/incubator/src/org.apache.sis.referencing.dggs/main/org/apache/sis/storage/dggs/DiscreteGlobalGridGeometry.java @@ -35,6 +35,7 @@ import org.apache.sis.referencing.dggs.DiscreteGlobalGrid; import org.apache.sis.referencing.dggs.DiscreteGlobalGridHierarchy; import org.apache.sis.referencing.dggs.DiscreteGlobalGridReferenceSystem; import org.apache.sis.referencing.dggs.Zone; +import org.apache.sis.referencing.operation.transform.TransformFactoryException; import org.apache.sis.storage.rs.CodeTransform; import org.apache.sis.storage.rs.CodedGeometry; import org.apache.sis.storage.rs.internal.shared.CodeTransforms; @@ -164,7 +165,7 @@ public class DiscreteGlobalGridGeometry extends CodedGeometry { try { trs = CRS.findOperation(baseCrs, crs, null).getMathTransform(); } catch (FactoryException ex) { - throw new TransformException(ex); + throw new TransformFactoryException(ex); } } else { return getEnvelope();
