SOLR-8166: Add some null checks

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1712677 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Uwe Schindler 2015-11-04 22:32:00 +00:00
parent 6f5b28be8a
commit 74f354a5a1
1 changed files with 15 additions and 1 deletions

View File

@ -24,7 +24,9 @@ import java.beans.PropertyDescriptor;
import java.beans.PropertyEditor;
import java.beans.PropertyEditorManager;
import java.io.InputStream;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import org.apache.solr.core.SolrResourceLoader;
@ -88,7 +90,16 @@ public class ParseContextConfig {
final String propertyValue = xmlPropertyAttributes.getNamedItem("value").getNodeValue();
final PropertyDescriptor propertyDescriptor = descriptorMap.get(propertyName);
propertyDescriptor.getWriteMethod().invoke(instance, getValueFromString(propertyDescriptor.getPropertyType(), propertyValue));
if (propertyDescriptor == null) {
throw new IllegalArgumentException(String.format(Locale.ENGLISH, "Unknown bean property %s in class %s",
propertyName, interfaceClass.getName()));
}
final Method method = propertyDescriptor.getWriteMethod();
if (method == null) {
throw new IllegalArgumentException(String.format(Locale.ENGLISH, "Cannot set bean property %s in class %s (no write method available)",
propertyName, interfaceClass.getName()));
}
method.invoke(instance, getValueFromString(propertyDescriptor.getPropertyType(), propertyValue));
}
entries.put(interfaceClass, instance);
@ -97,6 +108,9 @@ public class ParseContextConfig {
private Object getValueFromString(Class<?> targetType, String text) {
final PropertyEditor editor = PropertyEditorManager.findEditor(targetType);
if (editor == null) {
throw new IllegalArgumentException("Cannot set properties of type " + targetType.getName());
}
editor.setAsText(text);
return editor.getValue();
}