BUG-1026: do not mask unexpected exceptions 58/7158/1
authorRobert Varga <rovarga@cisco.com>
Sun, 18 May 2014 13:41:53 +0000 (15:41 +0200)
committerRobert Varga <rovarga@cisco.com>
Sun, 18 May 2014 14:29:03 +0000 (16:29 +0200)
This patch restructures the code such that we do not silently drop the
exception we may encounter during module info loading -- promote it
to an IllegalArgumentException.

This has the nice feature or also not masking any RuntimeExceptions we
may encounter.

Change-Id: I8a2c7108b589234c0c1350024dacb0d7f1ec4d72
Signed-off-by: Robert Varga <rovarga@cisco.com>
code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingSchemaContextUtils.java

index 078c090d27b37cea49cf8b9957eee9f641ffcba3..6645aba5741a64d4deb339ad2f1cd92dcffb15c2 100644 (file)
@@ -115,20 +115,23 @@ public class BindingSchemaContextUtils {
 
     private static Optional<DataNodeContainer> findFirstDataNodeContainerInRpc(final SchemaContext ctx,
             final Class<? extends DataObject> targetType) {
+        final YangModuleInfo moduleInfo;
         try {
-            YangModuleInfo moduleInfo = BindingReflections.getModuleInfo(targetType);
-            for(RpcDefinition rpc : ctx.getOperations()) {
-                String rpcNamespace = rpc.getQName().getNamespace().toString();
-                String rpcRevision = rpc.getQName().getFormattedRevision();
-                if(moduleInfo.getNamespace().equals(rpcNamespace) && moduleInfo.getRevision().equals(rpcRevision)) {
-                    Optional<DataNodeContainer> potential = findInputOutput(rpc,targetType.getSimpleName());
-                    if(potential.isPresent()) {
-                        return potential;
-                    }
+            moduleInfo = BindingReflections.getModuleInfo(targetType);
+        } catch (Exception e) {
+            throw new IllegalArgumentException(
+                    String.format("Failed to load module information for class %s", targetType), e);
+        }
+
+        for(RpcDefinition rpc : ctx.getOperations()) {
+            String rpcNamespace = rpc.getQName().getNamespace().toString();
+            String rpcRevision = rpc.getQName().getFormattedRevision();
+            if(moduleInfo.getNamespace().equals(rpcNamespace) && moduleInfo.getRevision().equals(rpcRevision)) {
+                Optional<DataNodeContainer> potential = findInputOutput(rpc,targetType.getSimpleName());
+                if(potential.isPresent()) {
+                    return potential;
                 }
             }
-        } catch (Exception e) {
-            // FIXME: Add logging
         }
         return Optional.absent();
     }