You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2015/05/11 13:10:54 UTC
svn commit: r1678723 - in
/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs:
DefaultDerivedCRS.java DefaultProjectedCRS.java
Author: desruisseaux
Date: Mon May 11 11:10:54 2015
New Revision: 1678723
URL: http://svn.apache.org/r1678723
Log:
Referencing: WKT formatting should be more tolerant to malformed CRS,
since we would like at least the 'toString()' method to work for investigating the problem.
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultDerivedCRS.java
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultProjectedCRS.java
Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultDerivedCRS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultDerivedCRS.java?rev=1678723&r1=1678722&r2=1678723&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultDerivedCRS.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultDerivedCRS.java [UTF-8] Mon May 11 11:10:54 2015
@@ -359,9 +359,18 @@ public class DefaultDerivedCRS extends A
*/
@Override
protected String formatTo(final Formatter formatter) {
+ final Conversion conversion = getConversionFromBase(); // Gives to users a chance to override.
+ if (conversion == null) {
+ /*
+ * Should never happen except temporarily at construction time, or if the user invoked the copy
+ * constructor with an invalid Conversion, or if the user overrides the getConversionFromBase()
+ * method. Delegates to the super-class method for avoiding a NullPointerException. That method
+ * returns 'null', which will cause the WKT to be declared invalid.
+ */
+ return super.formatTo(formatter);
+ }
WKTUtilities.appendName(this, formatter, null);
final boolean isWKT1 = (formatter.getConvention().majorVersion() == 1);
- final Conversion conversion = getConversionFromBase(); // Gives to users a chance to override.
/*
* Both WKT 1 and WKT 2 format the base CRS. But WKT 1 formats the MathTransform before the base CRS,
* while WKT 2 formats the conversion method and parameter values after the base CRS.
Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultProjectedCRS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultProjectedCRS.java?rev=1678723&r1=1678722&r2=1678723&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultProjectedCRS.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultProjectedCRS.java [UTF-8] Mon May 11 11:10:54 2015
@@ -46,6 +46,7 @@ import org.apache.sis.io.wkt.Formattable
import org.apache.sis.io.wkt.Formatter;
import org.apache.sis.io.wkt.Convention;
import org.apache.sis.util.ComparisonMode;
+import org.apache.sis.util.logging.Logging;
import static org.apache.sis.internal.referencing.WKTUtilities.toFormattable;
@@ -368,6 +369,14 @@ public class DefaultProjectedCRS extends
*/
@Override
protected String formatTo(final Formatter formatter) {
+ if (super.getConversionFromBase() == null) {
+ /*
+ * Should never happen except temporarily at construction time, or if the user invoked the copy constructor
+ * with an invalid Conversion. Delegates to the super-class method for avoiding a NullPointerException.
+ * That method returns 'null', which will cause the WKT to be declared invalid.
+ */
+ return super.formatTo(formatter);
+ }
WKTUtilities.appendName(this, formatter, null);
final Convention convention = formatter.getConvention();
final boolean isWKT1 = (convention.majorVersion() == 1);
@@ -445,7 +454,23 @@ public class DefaultProjectedCRS extends
* the lengths are different from the ones declared in the datum.
*/
if (param instanceof ParameterValue<?>) {
- final double value = ((ParameterValue<?>) param).doubleValue(axisUnit);
+ final double value;
+ try {
+ value = ((ParameterValue<?>) param).doubleValue(axisUnit);
+ } catch (IllegalStateException e) {
+ /*
+ * May happen if the 'conversionFromBase' parameter group does not provide values
+ * for "semi_major" or "semi_minor" axis length. This should not happen with SIS
+ * implementation, but may happen with user-defined map projection implementations.
+ * Since the intend of this check was to skip those parameters anyway, it is okay
+ * for the purpose of WKT formatting if there is no parameter for axis lengths.
+ */
+ Logging.recoverableException(DefaultProjectedCRS.class, "formatTo", e);
+ continue;
+ }
+ if (Double.isNaN(value)) {
+ continue;
+ }
final double expected = (name == Constants.SEMI_MINOR) // using '==' is okay here.
? ellipsoid.getSemiMinorAxis() : ellipsoid.getSemiMajorAxis();
if (value == expected) {