Author: desruisseaux Date: Fri Jan 8 19:39:23 2016 New Revision: 1723784 URL: http://svn.apache.org/viewvc?rev=1723784&view=rev Log: Fix a NullPointerException that occurred when constructing a DerivedCRS from a MathTransform. The NullPointerException occurred when asking for the targetCRS.getDatum() because the targetCRS construction is not yet completed at DefaultConversion construction time (cyclic references). The fix is to use only the CoordinateSystem and ignore the datum, which is not needed anyway when the MathTransform is already available.
Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ReferencingUtilities.java sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultConversion.java Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ReferencingUtilities.java URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ReferencingUtilities.java?rev=1723784&r1=1723783&r2=1723784&view=diff ============================================================================== --- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ReferencingUtilities.java [UTF-8] (original) +++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ReferencingUtilities.java [UTF-8] Fri Jan 8 19:39:23 2016 @@ -159,9 +159,9 @@ public final class ReferencingUtilities } /** - * Returns the ellipsoid used by the specified coordinate reference system, providing that - * the two first dimensions use an instance of {@link GeographicCRS}. Otherwise (i.e. if the - * two first dimensions are not geographic), returns {@code null}. + * Returns the ellipsoid used by the specified coordinate reference system, provided that the two first dimensions + * use an instance of {@link GeographicCRS}. Otherwise (i.e. if the two first dimensions are not geographic), + * returns {@code null}. * * <p>This method excludes geocentric CRS on intend. Some callers needs this exclusion as a way to identify * which CRS in a Geographic/Geocentric conversion is the geographic one. An other point of view is to said Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultConversion.java URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultConversion.java?rev=1723784&r1=1723783&r2=1723784&view=diff ============================================================================== --- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultConversion.java [UTF-8] (original) +++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultConversion.java [UTF-8] Fri Jan 8 19:39:23 2016 @@ -256,7 +256,11 @@ public class DefaultConversion extends A */ final DefaultMathTransformFactory.Context context = new DefaultMathTransformFactory.Context(); context.setSource(source); - context.setTarget(target.getCoordinateSystem()); + if (target instanceof GeneralDerivedCRS) { + context.setTarget(target.getCoordinateSystem()); // Using 'target' would be unsafe here. + } else { + context.setTarget(target); + } transform = ((DefaultMathTransformFactory) factory).createParameterizedTransform(parameters, context); parameters = Parameters.unmodifiable(context.getCompletedParameters()); } else { @@ -275,12 +279,10 @@ public class DefaultConversion extends A * ProjectedCRS), then DefaultMathTransformFactory has a specialized createBaseToDerived(…) * method for this job. */ - final CoordinateReferenceSystem sourceCRS = super.getSourceCRS(); - final CoordinateReferenceSystem targetCRS = super.getTargetCRS(); if (sourceCRS == null && targetCRS == null && factory instanceof DefaultMathTransformFactory) { final DefaultMathTransformFactory.Context context = new DefaultMathTransformFactory.Context(); - context.setSource(source); - context.setTarget(target); + context.setSource(source.getCoordinateSystem()); + context.setTarget(target.getCoordinateSystem()); // See comment on the other setTarget(…) call. transform = ((DefaultMathTransformFactory) factory).swapAndScaleAxes(transform, context); } else { /*