FELIX-392 Better handle unexpected issues when trying to get a activation or binding method by reflection
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@582225 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scr/src/main/java/org/apache/felix/scr/AbstractComponentManager.java b/scr/src/main/java/org/apache/felix/scr/AbstractComponentManager.java
index 7fb7a5c..2af4f95 100644
--- a/scr/src/main/java/org/apache/felix/scr/AbstractComponentManager.java
+++ b/scr/src/main/java/org/apache/felix/scr/AbstractComponentManager.java
@@ -19,6 +19,7 @@
package org.apache.felix.scr;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
@@ -765,8 +766,11 @@
*
* @throws NoSuchMethodException If no public or protected method with
* the given name can be found in the class or any of its super classes.
+ * @throws InvocationTargetException If an unexpected Throwable is caught
+ * trying to access the desired method.
*/
- static Method getMethod( Class clazz, String name, Class[] parameterTypes, boolean only ) throws NoSuchMethodException
+ static Method getMethod( Class clazz, String name, Class[] parameterTypes, boolean only )
+ throws NoSuchMethodException, InvocationTargetException
{
for ( ; clazz != null; clazz = clazz.getSuperclass() )
{
@@ -792,6 +796,12 @@
{
// ignore for now
}
+ catch ( Throwable throwable )
+ {
+ // unexpected problem accessing the method, don't let everything
+ // blow up in this situation, just throw a declared exception
+ throw new InvocationTargetException( throwable, "Unexpected problem trying to get method " + name );
+ }
}
// walked up the complete super class hierarchy and still not found
diff --git a/scr/src/main/java/org/apache/felix/scr/DependencyManager.java b/scr/src/main/java/org/apache/felix/scr/DependencyManager.java
index 44a7c16..8cdc00d 100644
--- a/scr/src/main/java/org/apache/felix/scr/DependencyManager.java
+++ b/scr/src/main/java/org/apache/felix/scr/DependencyManager.java
@@ -663,9 +663,13 @@
* @param parameterClassName the name of the class of the parameter that is
* passed to the method
* @return the method or null
- * @throws java.lang.ClassNotFoundException if the class was not found
+ * @throws ClassNotFoundException if the class for parameterClassName cannot
+ * be found.
+ * @throws InvocationTargetException If an unexpected error occurrs trying
+ * to get the method from the targetClass.
*/
private Method getBindingMethod( String methodname, Class targetClass, String parameterClassName )
+ throws InvocationTargetException
{
Class parameterClass = null;