lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cpoersc...@apache.org
Subject lucene-solr:master: SOLR-9161: SolrPluginUtils.invokeSetters now accommodates setter variants
Date Fri, 27 May 2016 19:32:57 GMT
Repository: lucene-solr
Updated Branches:
  refs/heads/master 3d22ea349 -> 50658dd93


SOLR-9161: SolrPluginUtils.invokeSetters now accommodates setter variants


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/50658dd9
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/50658dd9
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/50658dd9

Branch: refs/heads/master
Commit: 50658dd93d16eec37e906a24446146609cc93706
Parents: 3d22ea3
Author: Christine Poerschke <cpoerschke@apache.org>
Authored: Fri May 27 19:07:06 2016 +0100
Committer: Christine Poerschke <cpoerschke@apache.org>
Committed: Fri May 27 19:07:06 2016 +0100

----------------------------------------------------------------------
 solr/CHANGES.txt                                |  2 ++
 .../org/apache/solr/util/SolrPluginUtils.java   | 14 ++++++----
 .../apache/solr/util/SolrPluginUtilsTest.java   | 28 ++++++++++++++++++++
 3 files changed, 39 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/50658dd9/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 5ac3ff1..5a9c12a 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -337,6 +337,8 @@ Other Changes
 
 * SOLR-9110: Move JoinFromCollection- SubQueryTransformer- BlockJoinFacet- Distrib Tests
to SolrCloudTestCase  (Mikhail Khludnev)
 
+* SOLR-9161: SolrPluginUtils.invokeSetters now accommodates setter variants (Christine Poerschke)
+
 ==================  6.0.1 ==================
 (No Changes)
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/50658dd9/solr/core/src/java/org/apache/solr/util/SolrPluginUtils.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/util/SolrPluginUtils.java b/solr/core/src/java/org/apache/solr/util/SolrPluginUtils.java
index b30cc06..33c108d 100644
--- a/solr/core/src/java/org/apache/solr/util/SolrPluginUtils.java
+++ b/solr/core/src/java/org/apache/solr/util/SolrPluginUtils.java
@@ -1066,8 +1066,8 @@ public class SolrPluginUtils {
       String key = entry.getKey();
       String setterName = "set" + String.valueOf(Character.toUpperCase(key.charAt(0))) +
key.substring(1);
       try {
-        final Method method = findSetter(clazz, setterName, key);
         final Object val = entry.getValue();
+        final Method method = findSetter(clazz, setterName, key, val.getClass());
         method.invoke(bean, val);
       } catch (InvocationTargetException | IllegalAccessException e1) {
         throw new RuntimeException("Error invoking setter " + setterName + " on class : "
+ clazz.getName(), e1);
@@ -1075,10 +1075,14 @@ public class SolrPluginUtils {
     }
   }
 
-  private static Method findSetter(Class<?> clazz, String setterName, String key) {
-    for (Method m : clazz.getMethods()) {
-      if (m.getName().equals(setterName) && m.getParameterTypes().length == 1) {
-        return m;
+  private static Method findSetter(Class<?> clazz, String setterName, String key, Class<?>
paramClazz) {
+    try {
+      return clazz.getMethod(setterName, new Class<?>[] { paramClazz });
+    } catch (NoSuchMethodException e) {
+      for (Method m : clazz.getMethods()) {
+        if (m.getName().equals(setterName) && m.getParameterTypes().length == 1)
{
+          return m;
+        }
       }
     }
     throw new RuntimeException("No setter corrresponding to '" + key + "' in " + clazz.getName());

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/50658dd9/solr/core/src/test/org/apache/solr/util/SolrPluginUtilsTest.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/util/SolrPluginUtilsTest.java b/solr/core/src/test/org/apache/solr/util/SolrPluginUtilsTest.java
index 33e9291..fc50680 100644
--- a/solr/core/src/test/org/apache/solr/util/SolrPluginUtilsTest.java
+++ b/solr/core/src/test/org/apache/solr/util/SolrPluginUtilsTest.java
@@ -455,6 +455,34 @@ public class SolrPluginUtilsTest extends SolrTestCaseJ4 {
     assertEquals(3, q.build().getMinimumNumberShouldMatch());
   }
 
+  private class InvokeSettersTestClass {
+    private float aFloat = random().nextFloat();
+    public float getAFloat() {
+      return aFloat;
+    }
+    public void setAFloat(float aFloat) {
+      this.aFloat = aFloat;
+    }
+    public void setAFloat(String aFloat) {
+      this.aFloat = Float.parseFloat(aFloat);
+    }
+  }
+
+  @Test
+  public void testInvokeSetters() {
+    final Float theFloat = new Float(random().nextFloat());
+    implTestInvokeSetters(theFloat, theFloat);
+    implTestInvokeSetters(theFloat, theFloat.toString());
+  }
+
+  public void implTestInvokeSetters(final Float theFloat, final Object theFloatObject) {
+    final InvokeSettersTestClass bean = new InvokeSettersTestClass();
+    final Map<String,Object> initArgs = new HashMap<>();
+    initArgs.put("aFloat", theFloatObject);
+    SolrPluginUtils.invokeSetters(bean, initArgs.entrySet());
+    assertEquals(bean.getAFloat(), theFloat.floatValue(), 0.0);
+  }
+
   /** macro */
   public String pe(CharSequence s) {
     return SolrPluginUtils.partialEscape(s).toString();


Mime
View raw message