mirror of https://github.com/apache/lucene.git
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:
parent
6f5b28be8a
commit
74f354a5a1
|
@ -24,7 +24,9 @@ import java.beans.PropertyDescriptor;
|
||||||
import java.beans.PropertyEditor;
|
import java.beans.PropertyEditor;
|
||||||
import java.beans.PropertyEditorManager;
|
import java.beans.PropertyEditorManager;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.apache.solr.core.SolrResourceLoader;
|
import org.apache.solr.core.SolrResourceLoader;
|
||||||
|
@ -88,7 +90,16 @@ public class ParseContextConfig {
|
||||||
final String propertyValue = xmlPropertyAttributes.getNamedItem("value").getNodeValue();
|
final String propertyValue = xmlPropertyAttributes.getNamedItem("value").getNodeValue();
|
||||||
|
|
||||||
final PropertyDescriptor propertyDescriptor = descriptorMap.get(propertyName);
|
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);
|
entries.put(interfaceClass, instance);
|
||||||
|
@ -97,6 +108,9 @@ public class ParseContextConfig {
|
||||||
|
|
||||||
private Object getValueFromString(Class<?> targetType, String text) {
|
private Object getValueFromString(Class<?> targetType, String text) {
|
||||||
final PropertyEditor editor = PropertyEditorManager.findEditor(targetType);
|
final PropertyEditor editor = PropertyEditorManager.findEditor(targetType);
|
||||||
|
if (editor == null) {
|
||||||
|
throw new IllegalArgumentException("Cannot set properties of type " + targetType.getName());
|
||||||
|
}
|
||||||
editor.setAsText(text);
|
editor.setAsText(text);
|
||||||
return editor.getValue();
|
return editor.getValue();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue