Index: OSGiServiceFactory.java =================================================================== --- OSGiServiceFactory.java (revision 56427) +++ OSGiServiceFactory.java (working copy) @@ -41,6 +41,7 @@ package org.glassfish.osgicdi.impl; import java.lang.reflect.InvocationHandler; +import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Proxy; import java.lang.reflect.Type; @@ -231,7 +232,19 @@ debug ("looking a service as this is set to DYNAMIC=true"); final Object instanceToUse = lookupService(svcInjectionPoint); debug("calling Method " + method + " on proxy"); - return method.invoke(instanceToUse, args); + + //see [GLASSFISH-18370] And java doc of UndeclaredThrowableException + //when InvocationTargetException happened, we must get the real cause + //of InvocationTargetException + //Tang Yong(tangyong@cn.fujitsu.com) added 2012/07/20 + try{ + return method.invoke(instanceToUse, args); + }catch(InvocationTargetException e){ + if (e.getCause() != null){ + throw e.getCause(); + } + throw new Throwable(e); + } } } @@ -328,7 +341,19 @@ debug ("Using the service that was looked up earlier" + " as this is set to DYNAMIC=false"); debug("Calling Method " + method + " on Proxy"); - return method.invoke(instanceToUse, args); + + //see [GLASSFISH-18370] And java doc of UndeclaredThrowableException + //when InvocationTargetException happened, we must get the real cause + //of InvocationTargetException + //Tang Yong(tangyong@cn.fujitsu.com) added 2012/07/20 + try{ + return method.invoke(instanceToUse, args); + }catch(InvocationTargetException e){ + if (e.getCause() != null){ + throw e.getCause(); + } + throw new Throwable(e); + } } return null; }