Bug 6564: Fix UndeclaredThrowableException from Proxy 12/53412/1
authorMichael Vorburger <vorburger@redhat.com>
Thu, 16 Mar 2017 15:47:37 +0000 (16:47 +0100)
committerMichael Vorburger <vorburger@redhat.com>
Thu, 16 Mar 2017 15:47:37 +0000 (16:47 +0100)
from LegacyEntityOwnershipServiceProviderModule

also see
http://stackoverflow.com/questions/3715298/dynamic-proxy-and-checked-exceptions
and e.g.
https://amitstechblog.wordpress.com/2011/07/24/java-proxies-and-undeclaredthrowableexception/

Change-Id: I64d0789d1c136796610c4939337185173f90cd0a
Signed-off-by: Michael Vorburger <vorburger@redhat.com>
opendaylight/md-sal/sal-dom-config/src/main/java/org/opendaylight/controller/config/yang/config/legacy_entity_ownership_service_provider/LegacyEntityOwnershipServiceProviderModule.java

index e2585ac..5fe9ff9 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.controller.config.yang.config.legacy_entity_ownership_s
 
 import com.google.common.reflect.AbstractInvocationHandler;
 import com.google.common.reflect.Reflection;
+import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import org.opendaylight.controller.config.api.DependencyResolver;
 import org.opendaylight.controller.config.api.ModuleIdentifier;
@@ -50,7 +51,14 @@ public class LegacyEntityOwnershipServiceProviderModule extends AbstractLegacyEn
                     tracker.close();
                     return null;
                 } else {
-                    return method.invoke(service, args);
+                    try {
+                        return method.invoke(service, args);
+                    } catch (InvocationTargetException e) {
+                        // https://bugs.opendaylight.org/show_bug.cgi?id=6564
+                        // http://stackoverflow.com/a/10719613/421602
+                        // https://amitstechblog.wordpress.com/2011/07/24/java-proxies-and-undeclaredthrowableexception/
+                        throw e.getCause();
+                    }
                 }
             }
         });

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.