NIFI-4050: Fixed NPE at AbstractConfiguredComponent.validate

This closes #1905.

Signed-off-by: Bryan Bende <bbende@apache.org>
This commit is contained in:
Koji Kawamura 2017-06-09 17:28:23 +09:00 committed by Bryan Bende
parent 47165afc0c
commit 69613f29c9
No known key found for this signature in database
GPG Key ID: A0DDA9ED50711C39

View File

@ -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);
}
}