sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1800512 - /sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/GeodeticObjectFactory.java
Date Sat, 01 Jul 2017 15:48:06 GMT
Author: desruisseaux
Date: Sat Jul  1 15:48:06 2017
New Revision: 1800512

URL: http://svn.apache.org/viewvc?rev=1800512&view=rev
Log:
Preserve in FactoryException the message explaining why the parsing failed.

Modified:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/GeodeticObjectFactory.java

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/GeodeticObjectFactory.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/GeodeticObjectFactory.java?rev=1800512&r1=1800511&r2=1800512&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/GeodeticObjectFactory.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/GeodeticObjectFactory.java
[UTF-8] Sat Jul  1 15:48:06 2017
@@ -62,6 +62,7 @@ import org.apache.sis.util.resources.Err
 import org.apache.sis.util.logging.Logging;
 import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.io.wkt.Parser;
+import org.apache.sis.util.Exceptions;
 import org.apache.sis.xml.XML;
 
 
@@ -1557,7 +1558,26 @@ public class GeodeticObjectFactory exten
         try {
             object = XML.unmarshal(xml);
         } catch (JAXBException e) {
-            throw new FactoryException(e.getLocalizedMessage(), e);
+            /*
+             * The JAXB exception if often a wrapper around other exceptions, sometime InvocationTargetException.
+             * The exception cause is called "linked exception" by JAXB, presumably because
it predates standard
+             * chained exception mechanism introduced in Java 1.4. The JAXB linked exceptions
do not propagate the
+             * error message, so we have to take it from the cause, skipping InvocationTargetException
since they
+             * are wrapper for other causes. If the cause is a JAXBException, we will keep
it as the declared cause
+             * for simplifying the stack trace.
+             */
+            String message = e.getLocalizedMessage();
+            Throwable cause = e.getCause();
+            if (cause instanceof Exception) {
+                cause = Exceptions.unwrap((Exception) cause);
+                if (cause instanceof JAXBException) {
+                    e = (JAXBException) cause;
+                }
+                if (message == null) {
+                    message = cause.getLocalizedMessage();
+                }
+            }
+            throw new FactoryException(message, e);
         }
         if (object instanceof CoordinateReferenceSystem) {
             return (CoordinateReferenceSystem) object;



Mime
View raw message