sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1795905 - /sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyAccessor.java
Date Tue, 23 May 2017 12:45:48 GMT
Author: desruisseaux
Date: Tue May 23 12:45:48 2017
New Revision: 1795905

URL: http://svn.apache.org/viewvc?rev=1795905&view=rev
Log:
Fix an IllegalArgumentException when a property is defined in the implementation class but
not in the interface.
This happen on Apache SIS trunk during the transition from ISO 19115:2003 to ISO 19115:2014.

Modified:
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyAccessor.java

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyAccessor.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyAccessor.java?rev=1795905&r1=1795904&r2=1795905&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyAccessor.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyAccessor.java
[UTF-8] Tue May 23 12:45:48 2017
@@ -702,9 +702,29 @@ class PropertyAccessor {
         try {
             return method.invoke(metadata, (Object[]) null);
         } catch (IllegalAccessException e) {
-            // Should never happen since 'getters' should contains only public methods.
-            throw new AssertionError(e);
+            /*
+             * Should never happen since 'getters' should contains only public methods.
+             */
+            throw new AssertionError(method.toString(), e);
+        } catch (IllegalArgumentException e) {
+            /*
+             * May happen if the getter method is defined only in the implementation class,
not in the interface,
+             * but the given metadata object is an instance of another implementation class
than the expected one.
+             *
+             * Example: CI_Citation.graphics didn't existed in ISO 19115:2003 and has been
added in ISO 19115:2014.
+             * Consequently there is no Citation.getGraphics() method in GeoAPI 3.0 interfaces
(only in GeoAPI 3.1),
+             * but there is a DefaultCitation.getGraphics() method in Apache SIS implementation
since SIS is a little
+             * bit ahead of GeoAPI. But if the 'metadata' argument is another implementation
of the Citation interface,
+             * attempt to invoke DefaultCitation.getGraphics() will fail with IllegalArgumentException.
+             */
+            if (!method.getDeclaringClass().isInstance(metadata)) {
+                return null;
+            }
+            throw e;                                // Exception thrown for another reason.
This is probably a bug.
         } catch (InvocationTargetException e) {
+            /*
+             * Exception in user code (not a wrong usage of reflection).
+             */
             final Throwable cause = e.getTargetException();
             if (cause instanceof RuntimeException) {
                 throw (RuntimeException) cause;



Mime
View raw message