felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r1692035 - /felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/helper/Annotations.java
Date Mon, 20 Jul 2015 22:32:56 GMT
Author: djencks
Date: Mon Jul 20 22:32:56 2015
New Revision: 1692035

URL: http://svn.apache.org/r1692035
Log:
FELIX-4968 Throw coercion exceptions when members are accessed

Modified:
    felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/helper/Annotations.java

Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/helper/Annotations.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/helper/Annotations.java?rev=1692035&r1=1692034&r2=1692035&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/helper/Annotations.java (original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/helper/Annotations.java Mon Jul
20 22:32:56 2015
@@ -54,19 +54,26 @@ public class Annotations
                 complexFields.put(key, method);
                 continue;
             }
-            if (returnType.isArray())
+            try
             {
-                Class<?> componentType = returnType.getComponentType();
-                if ( componentType.isInterface() || componentType.isAnnotation())
+                if (returnType.isArray())
                 {
-                    complexFields.put(key, method);
-                    continue;
+                    Class<?> componentType = returnType.getComponentType();
+                    if (componentType.isInterface() || componentType.isAnnotation())
+                    {
+                        complexFields.put(key, method);
+                        continue;
+                    }
+                    cooked = coerceToArray(componentType, raw, b);
+                }
+                else
+                {
+                    cooked = Coercions.coerce(returnType, raw, b);
                 }
-                cooked = coerceToArray(componentType, raw, b);
             }
-            else
+            catch (ComponentException e)
             {
-                cooked = Coercions.coerce( returnType, raw, b );
+                cooked = new Invalid(e);
             }
             m.put( name, cooked );
         }
@@ -106,7 +113,7 @@ public class Annotations
             {
                 for (Method method: complexFields.values())
                 {
-                    m.put(method.getName(), Handler.INVALID);
+                    m.put(method.getName(), new Invalid("Invalid annotation member type"
+ method.getReturnType().getName() + " for member: " + method.getName()));
                 }
             }
         }
@@ -213,9 +220,8 @@ public class Annotations
         return b.toString();
     }
 
-    private static class Handler implements InvocationHandler 
+    private final static class Handler implements InvocationHandler 
     {
-        private final static Object INVALID = new Object();
         private final Map<String, Object> values;
        
         public Handler(Map<String, Object> values)
@@ -226,14 +232,33 @@ public class Annotations
         public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
         {
             Object value = values.get(method.getName());
-            if (INVALID == value)
+            if (value instanceof Invalid)
             {
-                throw new ComponentException(
-                    "Invalid annotation member type" + method.getReturnType().getName() +
" for member: " + method.getName());
+                throw new ComponentException(((Invalid)value).getMessage());
             }
             return value;
         }
         
     }
+    
+    private final static class Invalid 
+    {
+        private final String message;
+        
+        public Invalid(ComponentException e)
+        {
+            this.message = e.getMessage();
+        }
+        
+        public Invalid(String message)
+        {
+            this.message = message;
+        }
+
+        public String getMessage()
+        {
+            return message;
+        }
+    }
 
 }



Mime
View raw message