From 245e4839d1e50ed05a59a2f2ee82be713cc7e6fc Mon Sep 17 00:00:00 2001 From: Chris Hostetter Date: Wed, 1 Jun 2016 09:58:27 -0700 Subject: [PATCH] Revert "SOLR-9161: SolrPluginUtils.invokeSetters now accommodates setter variants" This reverts commit 50658dd93d16eec37e906a24446146609cc93706. Conflicts: solr/CHANGES.txt --- solr/CHANGES.txt | 2 -- .../org/apache/solr/util/SolrPluginUtils.java | 14 ++++------ .../apache/solr/util/SolrPluginUtilsTest.java | 28 ------------------- 3 files changed, 5 insertions(+), 39 deletions(-) diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index d395dfc1d4b..d0a0cb8f612 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -344,8 +344,6 @@ Other Changes * SOLR-9110: Move JoinFromCollection- SubQueryTransformer- BlockJoinFacet- Distrib Tests to SolrCloudTestCase (Mikhail Khludnev) -* SOLR-9161: SolrPluginUtils.invokeSetters now accommodates setter variants (Christine Poerschke) - * SOLR-9136: Separate out the error statistics into server-side error vs client-side error (Jessica Cheng Mallet via Erick Erickson) 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 33c108d3b90..b30cc06ba5e 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,14 +1075,10 @@ public class SolrPluginUtils { } } - 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; - } + 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; } } throw new RuntimeException("No setter corrresponding to '" + key + "' in " + clazz.getName()); 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 fc506807630..33e9291c703 100644 --- a/solr/core/src/test/org/apache/solr/util/SolrPluginUtilsTest.java +++ b/solr/core/src/test/org/apache/solr/util/SolrPluginUtilsTest.java @@ -455,34 +455,6 @@ 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 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();