Skip to content

Commit 9b4c050

Browse files
committed
[PAXCDI-192] Unwrap exceptions in proxy invocation handlers
1 parent 22ac037 commit 9b4c050

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

pax-cdi-extension/src/main/java/org/ops4j/pax/cdi/extension/impl/client/DynamicInvocationHandler.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818
package org.ops4j.pax.cdi.extension.impl.client;
1919

20+
import java.lang.reflect.InvocationTargetException;
2021
import java.lang.reflect.Method;
2122
import java.util.concurrent.Callable;
2223

@@ -25,6 +26,7 @@
2526
import org.ops4j.pax.cdi.extension.impl.compat.OsgiScopeUtils;
2627
import org.ops4j.pax.cdi.extension.impl.compat.ServiceObjectsWrapper;
2728
import org.ops4j.pax.cdi.extension.impl.util.InjectionPointOsgiUtils;
29+
import org.ops4j.pax.cdi.spi.util.Exceptions;
2830
import org.ops4j.pax.swissbox.core.ContextClassLoaderUtils;
2931
import org.osgi.framework.ServiceReference;
3032

@@ -64,7 +66,12 @@ public Object invoke(Object proxy, final Method method, final Object[] args) thr
6466

6567
@Override
6668
public Object call() throws Exception {
67-
return method.invoke(service, args);
69+
try {
70+
return method.invoke(service, args);
71+
}
72+
catch (InvocationTargetException exc) {
73+
throw Exceptions.unchecked(exc.getCause());
74+
}
6875
}
6976
});
7077
serviceObjects.ungetService(service);

pax-cdi-extension/src/main/java/org/ops4j/pax/cdi/extension/impl/client/StaticInvocationHandler.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818
package org.ops4j.pax.cdi.extension.impl.client;
1919

20+
import java.lang.reflect.InvocationTargetException;
2021
import java.lang.reflect.Method;
2122
import java.util.concurrent.Callable;
2223

@@ -25,6 +26,7 @@
2526
import org.ops4j.pax.cdi.extension.impl.compat.OsgiScopeUtils;
2627
import org.ops4j.pax.cdi.extension.impl.compat.ServiceObjectsWrapper;
2728
import org.ops4j.pax.cdi.extension.impl.util.InjectionPointOsgiUtils;
29+
import org.ops4j.pax.cdi.spi.util.Exceptions;
2830
import org.ops4j.pax.swissbox.core.ContextClassLoaderUtils;
2931
import org.osgi.framework.ServiceException;
3032
import org.osgi.framework.ServiceReference;
@@ -71,7 +73,12 @@ public Object invoke(Object proxy, final Method method, final Object[] args) thr
7173
@Override
7274
public Object call() throws Exception {
7375
if (service != null) {
74-
return method.invoke(service, args);
76+
try {
77+
return method.invoke(service, args);
78+
}
79+
catch (InvocationTargetException exc) {
80+
throw Exceptions.unchecked(exc.getCause());
81+
}
7582
}
7683
return null;
7784
}

pax-cdi-spi/src/main/java/org/ops4j/pax/cdi/spi/util/Exceptions.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ private Exceptions() {
5555
* checked exception
5656
* @return syntactically, a runtime exception (but never actually returns)
5757
*/
58-
public static RuntimeException unchecked(Exception exc) {
58+
public static RuntimeException unchecked(Throwable exc) {
5959
Exceptions.<RuntimeException> adapt(exc);
6060
return null;
6161
}
6262

6363
@SuppressWarnings("unchecked")
64-
private static <T extends Exception> void adapt(Exception exc) throws T {
64+
private static <T extends Exception> void adapt(Throwable exc) throws T {
6565
throw (T) exc;
6666
}
6767
}

0 commit comments

Comments
 (0)