Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
AMBARI-25327 : Prevent NPE for bindNotificationDispatchers and getSer…
…viceConfigVersionRequest (#3037)

* AMBARI-25327 : Prevent NPE for bindNotificationDispatchers and getServiceConfigVersionRequest

* minor change

* logging null classname instance
  • Loading branch information
virajjasani authored and Akhilsnaik committed Oct 16, 2019
1 parent b066df1 commit f6aec3286da30d42c7faef2e84e88b968bcdf040
Showing 2 changed files with 40 additions and 25 deletions.
@@ -666,25 +666,30 @@ protected Set<BeanDefinition> bindNotificationDispatchers(Set<BeanDefinition> be
// the dispatch factory
for (BeanDefinition beanDefinition : beanDefinitions) {
String className = beanDefinition.getBeanClassName();
Class<?> clazz = ClassUtils.resolveClassName(className,
ClassUtils.getDefaultClassLoader());

try {
NotificationDispatcher dispatcher;
if (clazz.equals(AmbariSNMPDispatcher.class)) {
dispatcher = (NotificationDispatcher) clazz.getConstructor(Integer.class).newInstance(configuration.getAmbariSNMPUdpBindPort());
} else if (clazz.equals(SNMPDispatcher.class)) {
dispatcher = (NotificationDispatcher) clazz.getConstructor(Integer.class).newInstance(configuration.getSNMPUdpBindPort());
} else {
dispatcher = (NotificationDispatcher) clazz.newInstance();
if (className != null) {
Class<?> clazz = ClassUtils.resolveClassName(className,
ClassUtils.getDefaultClassLoader());
try {
NotificationDispatcher dispatcher;
if (clazz.equals(AmbariSNMPDispatcher.class)) {
dispatcher = (NotificationDispatcher) clazz.getConstructor(Integer.class)
.newInstance(configuration.getAmbariSNMPUdpBindPort());
} else if (clazz.equals(SNMPDispatcher.class)) {
dispatcher = (NotificationDispatcher) clazz.getConstructor(Integer.class)
.newInstance(configuration.getSNMPUdpBindPort());
} else {
dispatcher = (NotificationDispatcher) clazz.newInstance();
}
dispatchFactory.register(dispatcher.getType(), dispatcher);
bind((Class<NotificationDispatcher>) clazz).toInstance(dispatcher);
LOG.info("Binding and registering notification dispatcher {}", clazz);
} catch (Exception exception) {
LOG.error("Unable to bind and register notification dispatcher {}",
clazz, exception);
}
dispatchFactory.register(dispatcher.getType(), dispatcher);
bind((Class<NotificationDispatcher>) clazz).toInstance(dispatcher);

LOG.info("Binding and registering notification dispatcher {}", clazz);
} catch (Exception exception) {
LOG.error("Unable to bind and register notification dispatcher {}",
clazz, exception);
} else {
LOG.error("Binding and registering notification dispatcher is not possible for" +
" beanDefinition: {} in the absence of className", beanDefinition);
}
}

@@ -466,16 +466,26 @@ protected static ServiceConfigVersionRequest getServiceConfigVersionRequest(Stri
String absCategory = PropertyHelper.getPropertyCategory(entry.getKey());
String propName = PropertyHelper.getPropertyName(entry.getKey());

if (absCategory.startsWith(parentCategory + "/desired_service_config_version")) {
if (absCategory != null &&
absCategory.startsWith(parentCategory + "/desired_service_config_version")) {
serviceConfigVersionRequest =
(serviceConfigVersionRequest ==null ) ? new ServiceConfigVersionRequest() : serviceConfigVersionRequest;

if (propName.equals("service_name"))
serviceConfigVersionRequest.setServiceName(entry.getValue().toString());
else if (propName.equals("service_config_version"))
serviceConfigVersionRequest.setVersion(Long.valueOf(entry.getValue().toString()));
else if (propName.equals("service_config_version_note")) {
serviceConfigVersionRequest.setNote(entry.getValue().toString());
if (propName != null) {
switch (propName) {
case "service_name": {
serviceConfigVersionRequest.setServiceName(entry.getValue().toString());
break;
}
case "service_config_version": {
serviceConfigVersionRequest.setVersion(Long.valueOf(entry.getValue().toString()));
break;
}
case "service_config_version_note": {
serviceConfigVersionRequest.setNote(entry.getValue().toString());
break;
}
}
}
}
}

0 comments on commit f6aec32

Please sign in to comment.