Repository: nifi
Updated Branches:
  refs/heads/master 47165afc0 -> 69613f29c


NIFI-4050: Fixed NPE at AbstractConfiguredComponent.validate

This closes #1905.

Signed-off-by: Bryan Bende <[email protected]>


Project: http://git-wip-us.apache.org/repos/asf/nifi/repo
Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/69613f29
Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/69613f29
Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/69613f29

Branch: refs/heads/master
Commit: 69613f29c90d5f5e757e80e6d89a3e7d34f028d0
Parents: 47165af
Author: Koji Kawamura <[email protected]>
Authored: Fri Jun 9 17:28:23 2017 +0900
Committer: Bryan Bende <[email protected]>
Committed: Fri Jun 23 13:58:22 2017 -0400

----------------------------------------------------------------------
 .../controller/AbstractConfiguredComponent.java | 23 +++++++++++++++-----
 1 file changed, 17 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/nifi/blob/69613f29/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/controller/AbstractConfiguredComponent.java
----------------------------------------------------------------------
diff --git 
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/controller/AbstractConfiguredComponent.java
 
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/controller/AbstractConfiguredComponent.java
index 40e81cc..76c5d7a 100644
--- 
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/controller/AbstractConfiguredComponent.java
+++ 
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/controller/AbstractConfiguredComponent.java
@@ -51,6 +51,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicReference;
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReentrantLock;
+import java.util.function.Consumer;
 
 public abstract class AbstractConfiguredComponent implements 
ConfigurableComponent, ConfiguredComponent {
     private static final Logger logger = 
LoggerFactory.getLogger(AbstractConfiguredComponent.class);
@@ -350,10 +351,25 @@ public abstract class AbstractConfiguredComponent 
implements ConfigurableCompone
                     final Class<? extends ControllerService> 
controllerServiceApiClass = descriptor.getControllerServiceDefinition();
                     final ClassLoader controllerServiceApiClassLoader = 
controllerServiceApiClass.getClassLoader();
 
+                    final Consumer<String> addValidationError = explanation -> 
validationResults.add(new ValidationResult.Builder()
+                            .input(controllerServiceId)
+                            .subject(descriptor.getDisplayName())
+                            .valid(false)
+                            .explanation(explanation)
+                            .build());
+
                     final Bundle controllerServiceApiBundle = 
ExtensionManager.getBundle(controllerServiceApiClassLoader);
+                    if (controllerServiceApiBundle == null) {
+                        addValidationError.accept(String.format("Unable to 
find bundle for ControllerService API class %s.", 
controllerServiceApiClass.getCanonicalName()));
+                        continue;
+                    }
                     final BundleCoordinate controllerServiceApiCoordinate = 
controllerServiceApiBundle.getBundleDetails().getCoordinate();
 
                     final Bundle controllerServiceBundle = 
ExtensionManager.getBundle(controllerServiceNode.getBundleCoordinate());
+                    if (controllerServiceBundle == null) {
+                        addValidationError.accept(String.format("Unable to 
find bundle for coordinate %s.", controllerServiceNode.getBundleCoordinate()));
+                        continue;
+                    }
                     final BundleCoordinate controllerServiceCoordinate = 
controllerServiceBundle.getBundleDetails().getCoordinate();
 
                     final boolean matchesApi = 
matchesApi(controllerServiceBundle, controllerServiceApiCoordinate);
@@ -369,12 +385,7 @@ public abstract class AbstractConfiguredComponent 
implements ConfigurableCompone
                                 .append(" from 
").append(controllerServiceApiCoordinate.getGroup()).append(" - 
").append(controllerServiceApiCoordinate.getId())
                                 .toString();
 
-                        validationResults.add(new ValidationResult.Builder()
-                                .input(controllerServiceId)
-                                .subject(descriptor.getDisplayName())
-                                .valid(false)
-                                .explanation(explanation)
-                                .build());
+                        addValidationError.accept(explanation);
                     }
 
                 }

Reply via email to