You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by ds...@apache.org on 2022/02/22 22:54:10 UTC

[solr] branch branch_9x updated: Minor: Utils.fromJSONResource should take a ClassLoader (#675)

This is an automated email from the ASF dual-hosted git repository.

dsmiley pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/solr.git


The following commit(s) were added to refs/heads/branch_9x by this push:
     new e48f382  Minor: Utils.fromJSONResource should take a ClassLoader (#675)
e48f382 is described below

commit e48f3827c7ccc1b3c470b33a1fc68311efed0c2f
Author: David Smiley <ds...@salesforce.com>
AuthorDate: Tue Feb 22 17:51:44 2022 -0500

    Minor: Utils.fromJSONResource should take a ClassLoader (#675)
    
    Not a bug necessarily but is better because it's presumptuous to assume the classloader of Utils (SolrJ)
---
 solr/core/src/java/org/apache/solr/core/ConfigOverlay.java            | 2 +-
 solr/core/src/java/org/apache/solr/core/SolrCore.java                 | 2 +-
 .../test/org/apache/solr/handler/TestSolrConfigHandlerConcurrent.java | 2 +-
 solr/solrj/src/java/org/apache/solr/common/util/Utils.java            | 4 ++--
 4 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/solr/core/src/java/org/apache/solr/core/ConfigOverlay.java b/solr/core/src/java/org/apache/solr/core/ConfigOverlay.java
index 2c66334..59cf5ed 100644
--- a/solr/core/src/java/org/apache/solr/core/ConfigOverlay.java
+++ b/solr/core/src/java/org/apache/solr/core/ConfigOverlay.java
@@ -174,7 +174,7 @@ public class ConfigOverlay implements MapSerializable {
   //The path maps to the xml xpath and value of 1 means it is a tag with a string value and value
   // of 0 means it is an attribute with string value
 
-  private static Map<?, ?> editable_prop_map = (Map<?, ?>) Utils.fromJSONResource("EditableSolrConfigAttributes.json");
+  private static Map<?, ?> editable_prop_map = (Map<?, ?>) Utils.fromJSONResource(ConfigOverlay.class.getClassLoader(), "EditableSolrConfigAttributes.json");
 
   public static boolean isEditableProp(String path, boolean isXpath, List<String> hierarchy) {
     return !(checkEditable(path, isXpath, hierarchy) == null);
diff --git a/solr/core/src/java/org/apache/solr/core/SolrCore.java b/solr/core/src/java/org/apache/solr/core/SolrCore.java
index dc3887d..d7169fc 100644
--- a/solr/core/src/java/org/apache/solr/core/SolrCore.java
+++ b/solr/core/src/java/org/apache/solr/core/SolrCore.java
@@ -3218,7 +3218,7 @@ public final class SolrCore implements SolrInfoBean, Closeable {
 
     static {
       @SuppressWarnings("unchecked")
-      Map<String,?> implicitPluginsInfo = (Map<String,?>) Utils.fromJSONResource("ImplicitPlugins.json");
+      Map<String,?> implicitPluginsInfo = (Map<String,?>) Utils.fromJSONResource(SolrCore.class.getClassLoader(), "ImplicitPlugins.json");
       @SuppressWarnings("unchecked")
       Map<String, Map<String,Object>> requestHandlers = (Map<String, Map<String, Object>>) implicitPluginsInfo.get(SolrRequestHandler.TYPE);
 
diff --git a/solr/core/src/test/org/apache/solr/handler/TestSolrConfigHandlerConcurrent.java b/solr/core/src/test/org/apache/solr/handler/TestSolrConfigHandlerConcurrent.java
index 968db78..3067511 100644
--- a/solr/core/src/test/org/apache/solr/handler/TestSolrConfigHandlerConcurrent.java
+++ b/solr/core/src/test/org/apache/solr/handler/TestSolrConfigHandlerConcurrent.java
@@ -55,7 +55,7 @@ public class TestSolrConfigHandlerConcurrent extends AbstractFullDistribZkTestBa
 
   @Test
   public void test() throws Exception {
-    Map<?, ?> editable_prop_map = (Map<?, ?>) Utils.fromJSONResource("EditableSolrConfigAttributes.json");
+    Map<?, ?> editable_prop_map = (Map<?, ?>) Utils.fromJSONResource(getClass().getClassLoader(), "EditableSolrConfigAttributes.json");
     Map<?, ?> caches = (Map<?, ?>) editable_prop_map.get("query");
 
     setupRestTestHarnesses();
diff --git a/solr/solrj/src/java/org/apache/solr/common/util/Utils.java b/solr/solrj/src/java/org/apache/solr/common/util/Utils.java
index 3193bad..78c0fdd 100644
--- a/solr/solrj/src/java/org/apache/solr/common/util/Utils.java
+++ b/solr/solrj/src/java/org/apache/solr/common/util/Utils.java
@@ -402,8 +402,8 @@ public class Utils {
     }
   }
 
-  public static Object fromJSONResource(String resourceName) {
-    final URL resource = Utils.class.getClassLoader().getResource(resourceName);
+  public static Object fromJSONResource(ClassLoader loader, String resourceName) {
+    final URL resource = loader.getResource(resourceName);
     if (null == resource) {
       throw new IllegalArgumentException("invalid resource name: " + resourceName);
     }