You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by dj...@apache.org on 2015/07/18 20:13:02 UTC

svn commit: r1691762 - /felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/helper/Annotations.java

Author: djencks
Date: Sat Jul 18 18:13:01 2015
New Revision: 1691762

URL: http://svn.apache.org/r1691762
Log:
FELIX-4965 throw ComponentException for invalid annotation member types

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=1691762&r1=1691761&r2=1691762&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 Sat Jul 18 18:13:01 2015
@@ -31,6 +31,7 @@ import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 import org.osgi.framework.Bundle;
+import org.osgi.service.component.ComponentException;
 
 public class Annotations
 {
@@ -70,39 +71,44 @@ public class Annotations
             m.put( name, cooked );
         }
         if (!complexFields.isEmpty())
-        {
-            if (!supportsInterfaces )
-            {
-            //error
-                return null;//??
-            }
-            Map<String, List<Map<String, Object>>> nested = extractSubMaps(complexFields.keySet(), props);
-            for (Map.Entry<String, Method> entry: complexFields.entrySet())
+        { 
+            if (supportsInterfaces )
             {
-                List<Map<String, Object>> proplist = nested.get(entry.getKey());
-                Method method = entry.getValue();
-                Class<?> returnType  = method.getReturnType();
-                if (returnType.isArray())
+                Map<String, List<Map<String, Object>>> nested = extractSubMaps(complexFields.keySet(), props);
+                for (Map.Entry<String, Method> entry: complexFields.entrySet())
                 {
-                    Class<?> componentType = returnType.getComponentType();
-                    Object result = Array.newInstance(componentType, proplist.size());
-                    for (int i = 0; i < proplist.size(); i++)
+                    List<Map<String, Object>> proplist = nested.get(entry.getKey());
+                    Method method = entry.getValue();
+                    Class<?> returnType  = method.getReturnType();
+                    if (returnType.isArray())
                     {
-                        Map<String, Object> rawElement = proplist.get(i);
-                        Object cooked = toObject(componentType, rawElement, b, supportsInterfaces);
-                        Array.set(result, i, cooked);
+                        Class<?> componentType = returnType.getComponentType();
+                        Object result = Array.newInstance(componentType, proplist.size());
+                        for (int i = 0; i < proplist.size(); i++)
+                        {
+                            Map<String, Object> rawElement = proplist.get(i);
+                            Object cooked = toObject(componentType, rawElement, b, supportsInterfaces);
+                            Array.set(result, i, cooked);
+                        }
+                        m.put(method.getName(), result);
                     }
-                    m.put(method.getName(), result);
-                }
-                else
-                {
-                    if (!proplist.isEmpty())
+                    else
                     {
-                        Object cooked = toObject(returnType, proplist.get(0), b, supportsInterfaces);
-                        m.put(method.getName(), cooked);
+                        if (!proplist.isEmpty())
+                        {
+                            Object cooked = toObject(returnType, proplist.get(0), b, supportsInterfaces);
+                            m.put(method.getName(), cooked);
+                        }
                     }
                 }
             }
+            else
+            {
+                for (Method method: complexFields.values())
+                {
+                    m.put(method.getName(), Handler.INVALID);
+                }
+            }
         }
         
         InvocationHandler h = new Handler(m);
@@ -209,7 +215,7 @@ public class Annotations
 
     private static class Handler implements InvocationHandler 
     {
-        
+        private final static Object INVALID = new Object();
         private final Map<String, Object> values;
        
         public Handler(Map<String, Object> values)
@@ -219,7 +225,13 @@ public class Annotations
 
         public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
         {
-            return values.get(method.getName());
+            Object value = values.get(method.getName());
+            if (INVALID == value)
+            {
+                throw new ComponentException(
+                    "Invalid annotation member type" + method.getReturnType().getName() + " for member: " + method.getName());
+            }
+            return value;
         }
         
     }