You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by ja...@apache.org on 2021/12/05 17:37:23 UTC
[solr] branch main updated: SOLR-15826 Simplify some code in SolrResourceLoader, consider PR feedback (#443)
This is an automated email from the ASF dual-hosted git repository.
janhoy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/solr.git
The following commit(s) were added to refs/heads/main by this push:
new d172b2c SOLR-15826 Simplify some code in SolrResourceLoader, consider PR feedback (#443)
d172b2c is described below
commit d172b2c7ae8ed534b3ec6ed8167f8736823a66a7
Author: Jan Høydahl <ja...@users.noreply.github.com>
AuthorDate: Sun Dec 5 18:37:17 2021 +0100
SOLR-15826 Simplify some code in SolrResourceLoader, consider PR feedback (#443)
---
.../org/apache/solr/core/SolrResourceLoader.java | 33 ++++++++--------------
.../apache/solr/schema/PrimitiveFieldTypeTest.java | 3 --
2 files changed, 11 insertions(+), 25 deletions(-)
diff --git a/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java b/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java
index bac4709..661b061 100644
--- a/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java
+++ b/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java
@@ -91,7 +91,7 @@ public class SolrResourceLoader implements ResourceLoader, Closeable, SolrClassL
};
private static final Charset UTF_8 = StandardCharsets.UTF_8;
public static final String SOLR_ALLOW_UNSAFE_RESOURCELOADING_PARAM = "solr.allow.unsafe.resourceloading";
- private boolean allowUnsafeResourceloading;
+ private final boolean allowUnsafeResourceloading;
private String name = "";
@@ -104,9 +104,9 @@ public class SolrResourceLoader implements ResourceLoader, Closeable, SolrClassL
private PackageListeningClassLoader schemaLoader ;
private PackageListeningClassLoader coreReloadingClassLoader ;
- private final List<SolrCoreAware> waitingForCore = Collections.synchronizedList(new ArrayList<SolrCoreAware>());
- private final List<SolrInfoBean> infoMBeans = Collections.synchronizedList(new ArrayList<SolrInfoBean>());
- private final List<ResourceLoaderAware> waitingForResources = Collections.synchronizedList(new ArrayList<ResourceLoaderAware>());
+ private final List<SolrCoreAware> waitingForCore = Collections.synchronizedList(new ArrayList<>());
+ private final List<SolrInfoBean> infoMBeans = Collections.synchronizedList(new ArrayList<>());
+ private final List<ResourceLoaderAware> waitingForResources = Collections.synchronizedList(new ArrayList<>());
private volatile boolean live;
@@ -274,12 +274,7 @@ public class SolrResourceLoader implements ResourceLoader, Closeable, SolrClassL
* @throws IOException on error
*/
public static List<URL> getURLs(Path libDir) throws IOException {
- return getURLs(libDir, new DirectoryStream.Filter<Path>() {
- @Override
- public boolean accept(Path entry) throws IOException {
- return true;
- }
- });
+ return getURLs(libDir, entry -> true);
}
/**
@@ -292,12 +287,7 @@ public class SolrResourceLoader implements ResourceLoader, Closeable, SolrClassL
*/
public static List<URL> getFilteredURLs(Path libDir, String regex) throws IOException {
final PathMatcher matcher = libDir.getFileSystem().getPathMatcher("regex:" + regex);
- return getURLs(libDir, new DirectoryStream.Filter<Path>() {
- @Override
- public boolean accept(Path entry) throws IOException {
- return matcher.matches(entry.getFileName());
- }
- });
+ return getURLs(libDir, entry -> matcher.matches(entry.getFileName()));
}
public Path getConfigPath() {
@@ -341,7 +331,7 @@ public class SolrResourceLoader implements ResourceLoader, Closeable, SolrClassL
Path instanceDir = getInstancePath().normalize();
Path inInstanceDir = getInstancePath().resolve(resource).normalize();
Path inConfigDir = instanceDir.resolve("conf").resolve(resource).normalize();
- if (inInstanceDir.startsWith(instanceDir) || allowUnsafeResourceloading) {
+ if (allowUnsafeResourceloading || inInstanceDir.startsWith(instanceDir)) {
// The resource is either inside instance dir or we allow unsafe loading, so allow testing if file exists
if (Files.exists(inConfigDir) && Files.isReadable(inConfigDir)) {
return Files.newInputStream(inConfigDir);
@@ -378,8 +368,7 @@ public class SolrResourceLoader implements ResourceLoader, Closeable, SolrClassL
}
Path inInstanceDir = instanceDir.resolve(resource).normalize();
Path inConfigDir = instanceDir.resolve("conf").resolve(resource).normalize();
- boolean isRelativeToInstanceDir = inInstanceDir.startsWith(instanceDir.normalize());
- if (isRelativeToInstanceDir || allowUnsafeResourceloading) {
+ if (allowUnsafeResourceloading || inInstanceDir.startsWith(instanceDir.normalize())) {
if (Files.exists(inConfigDir) && Files.isReadable(inConfigDir))
return inConfigDir.normalize().toString();
@@ -484,7 +473,7 @@ public class SolrResourceLoader implements ResourceLoader, Closeable, SolrClassL
}
}
}
- Class<? extends T> clazz = null;
+ Class<? extends T> clazz;
clazz = getPackageClass(cname, expectedType);
if(clazz != null) return clazz;
try {
@@ -588,10 +577,10 @@ public class SolrResourceLoader implements ResourceLoader, Closeable, SolrClassL
"Can not find class: " + cName + " in " + classLoader);
}
- T obj = null;
+ T obj;
try {
- Constructor<? extends T> constructor = null;
+ Constructor<? extends T> constructor;
try {
constructor = clazz.getConstructor(params);
obj = constructor.newInstance(args);
diff --git a/solr/core/src/test/org/apache/solr/schema/PrimitiveFieldTypeTest.java b/solr/core/src/test/org/apache/solr/schema/PrimitiveFieldTypeTest.java
index 3dd53c6..17c0c29 100644
--- a/solr/core/src/test/org/apache/solr/schema/PrimitiveFieldTypeTest.java
+++ b/solr/core/src/test/org/apache/solr/schema/PrimitiveFieldTypeTest.java
@@ -24,7 +24,6 @@ import java.util.Map;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.core.SolrConfig;
-import org.apache.solr.core.SolrResourceLoader;
import org.junit.Test;
/**
@@ -43,7 +42,6 @@ public class PrimitiveFieldTypeTest extends SolrTestCaseJ4 {
System.setProperty("enable.update.log", "false"); // schema12 doesn't support _version_
System.setProperty("solr.test.sys.prop1", "propone");
System.setProperty("solr.test.sys.prop2", "proptwo");
- System.setProperty(SolrResourceLoader.SOLR_ALLOW_UNSAFE_RESOURCELOADING_PARAM, "true");
initMap = new HashMap<>();
config = new SolrConfig(TEST_PATH().resolve("collection1"), testConfHome + "solrconfig.xml");
@@ -51,7 +49,6 @@ public class PrimitiveFieldTypeTest extends SolrTestCaseJ4 {
@Override
public void tearDown() throws Exception {
- System.clearProperty(SolrResourceLoader.SOLR_ALLOW_UNSAFE_RESOURCELOADING_PARAM);
super.tearDown();
}