BUG-1026: Better message when we fail lookup 50/7150/3
authorRobert Varga <rovarga@cisco.com>
Sun, 18 May 2014 07:05:04 +0000 (09:05 +0200)
committerRobert Varga <rovarga@cisco.com>
Sun, 18 May 2014 14:29:03 +0000 (16:29 +0200)
This turns a NPE into a checkArgument(), such that we emit proper
diagnostic information.

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

index a6bf37629818d798ebf459ee1da9282a7b594a3b..12b960c1a3b4d5b9c24f29d091576d19296a03d6 100644 (file)
@@ -276,8 +276,9 @@ class LazyGeneratedCodecRegistry implements //
 
     private DataSchemaNode getSchemaNode(final List<QName> path) {
         QName firstNode = path.get(0);
-        DataNodeContainer previous = currentSchema.findModuleByNamespaceAndRevision(firstNode.getNamespace(),
-                firstNode.getRevision());
+        DataNodeContainer previous = currentSchema.findModuleByNamespaceAndRevision(firstNode.getNamespace(), firstNode.getRevision());
+        Preconditions.checkArgument(previous != null, "Failed to find module %s for path %s", firstNode, path);
+
         Iterator<QName> iterator = path.iterator();
         while (iterator.hasNext()) {
             QName arg = iterator.next();
@@ -1110,7 +1111,7 @@ class LazyGeneratedCodecRegistry implements //
                         .loadClass(potential);
                 return Optional.of(tryToLoadImplementation(clazz));
             } catch (ClassNotFoundException e) {
-                LOG.warn("Failed to find class for augmentation of {}, reason: {}", potential, e.toString());
+                LOG.warn("Failed to find class for augmentation of {}", potential, e);
             }
             return Optional.absent();
         }
@@ -1120,7 +1121,6 @@ class LazyGeneratedCodecRegistry implements //
             AugmentationCodecWrapper<? extends Augmentation<?>> potentialImpl = getCodecForAugmentation(inputType);
             addImplementation(potentialImpl);
             return potentialImpl;
-
         }
 
         @Override
@@ -1134,10 +1134,9 @@ class LazyGeneratedCodecRegistry implements //
                 try {
                     tryToLoadImplementation(potential);
                 } catch (CodeGenerationException e) {
-                    LOG.warn("Failed to proactively generate augment coded for {}, reason: {}", type, e.toString());
+                    LOG.warn("Failed to proactively generate augment code for {}", type, e);
                 }
             }
-
         }
 
         @Override
@@ -1148,7 +1147,6 @@ class LazyGeneratedCodecRegistry implements //
                 if (!availableAugmentations.isEmpty()) {
                     updateAugmentationMapping(path,availableAugmentations);
                 }
-
             }
         }
 
@@ -1162,7 +1160,7 @@ class LazyGeneratedCodecRegistry implements //
                         potentialImpl.get().addApplicableFor(path,aug);
                     }
                 } else {
-                    LOG.warn("Could not find generated type for augmentation {} with childs {}.",aug,aug.getChildNodes());
+                    LOG.warn("Could not find generated type for augmentation {} with children {}", aug, aug.getChildNodes());
                 }
             }
             availableAugmentations.toString();