Fix NPE in AbstractFeatureWrapper 71/27971/1
authorTom Pantelis <tpanteli@brocade.com>
Mon, 5 Oct 2015 16:10:23 +0000 (12:10 -0400)
committerTony Tkacik <ttkacik@cisco.com>
Tue, 6 Oct 2015 15:18:12 +0000 (15:18 +0000)
Added check in ChildAwareFeatureWrapper#getChildFeatures to verify the
feature exists in the FeaturesService to avoid NPE. This is a similar
workaround as was done in FeatureConfigPusher for a bug in karaf where
the FeaturesService may mysteriously return null for an existing feature.

Change-Id: I006cd012e919ac206d70bb4ee5754c72f0f01b32
Signed-off-by: Tom Pantelis <tpanteli@brocade.com>
(cherry picked from commit e6076f69f57fe5918c66637414175c6229635841)

opendaylight/config/config-persister-feature-adapter/src/main/java/org/opendaylight/controller/configpusherfeature/internal/ChildAwareFeatureWrapper.java

index 2cb53ca560ec541cb325fb57058b57e2185539de..7da9b9f9a3663482c989e44cb9a8bab8da04c886 100644 (file)
@@ -58,15 +58,20 @@ public class ChildAwareFeatureWrapper extends AbstractFeatureWrapper implements
         if(dependencies != null) {
             for(Dependency dependency: dependencies) {
                 Feature fi = extractFeatureFromDependency(dependency);
-                if(fi != null){
-                    ChildAwareFeatureWrapper wrappedFeature = new ChildAwareFeatureWrapper(fi,featuresService);
-                    childFeatures.add(wrappedFeature);
+                if(fi != null) {
+                    if(featuresService.getFeature(fi.getName(), fi.getVersion()) == null) {
+                        LOG.warn("Feature: {}, {} is missing from features service. Skipping", fi.getName(), fi.getVersion());
+                    } else {
+                        ChildAwareFeatureWrapper wrappedFeature = new ChildAwareFeatureWrapper(fi,featuresService);
+                        childFeatures.add(wrappedFeature);
+                    }
                 }
             }
         }
         return childFeatures;
     }
 
+    @Override
     public LinkedHashSet<FeatureConfigSnapshotHolder> getFeatureConfigSnapshotHolders() throws Exception {
         LinkedHashSet <FeatureConfigSnapshotHolder> snapShotHolders = new LinkedHashSet<FeatureConfigSnapshotHolder>();
         for(ChildAwareFeatureWrapper c: getChildFeatures()) {