You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by us...@apache.org on 2015/11/04 23:33:58 UTC

svn commit: r1712678 - in /lucene/dev/branches/branch_5x: ./ solr/ solr/contrib/ solr/contrib/extraction/src/java/org/apache/solr/handler/extraction/ParseContextConfig.java

Author: uschindler
Date: Wed Nov  4 22:33:57 2015
New Revision: 1712678

URL: http://svn.apache.org/viewvc?rev=1712678&view=rev
Log:
Merged revision(s) 1712677 from lucene/dev/trunk:
SOLR-8166: Add some null checks

Modified:
    lucene/dev/branches/branch_5x/   (props changed)
    lucene/dev/branches/branch_5x/solr/   (props changed)
    lucene/dev/branches/branch_5x/solr/contrib/   (props changed)
    lucene/dev/branches/branch_5x/solr/contrib/extraction/src/java/org/apache/solr/handler/extraction/ParseContextConfig.java

Modified: lucene/dev/branches/branch_5x/solr/contrib/extraction/src/java/org/apache/solr/handler/extraction/ParseContextConfig.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/contrib/extraction/src/java/org/apache/solr/handler/extraction/ParseContextConfig.java?rev=1712678&r1=1712677&r2=1712678&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/contrib/extraction/src/java/org/apache/solr/handler/extraction/ParseContextConfig.java (original)
+++ lucene/dev/branches/branch_5x/solr/contrib/extraction/src/java/org/apache/solr/handler/extraction/ParseContextConfig.java Wed Nov  4 22:33:57 2015
@@ -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();
   }