Skip to content

Apache Lucene open-source search software

SOLR-11272: fix NPE from EmbeddedSolrServer on /admin/info/system

Mikhail Khludnev19a8be3c9f48
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 69be893f346..13b6ed7e3ff 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -99,6 +99,8 @@ Bug Fixes
* SOLR-11255: Fix occasional ConcurrentModificationException when using SolrInfoMBeanHandler. (ab)
+* SOLR-11272: fix NPE when EmbeddedSolrServer handles /admin/* request and so one (Stephen Allen via Mikhail Khludnev)
+
Optimizations
----------------------
diff --git a/solr/core/src/java/org/apache/solr/client/solrj/embedded/EmbeddedSolrServer.java b/solr/core/src/java/org/apache/solr/client/solrj/embedded/EmbeddedSolrServer.java
index def4250d158..0c7ea25f183 100644
--- a/solr/core/src/java/org/apache/solr/client/solrj/embedded/EmbeddedSolrServer.java
+++ b/solr/core/src/java/org/apache/solr/client/solrj/embedded/EmbeddedSolrServer.java
@@ -127,6 +127,7 @@ public class EmbeddedSolrServer extends SolrClient {
if (handler != null) {
try {
SolrQueryRequest req = _parser.buildRequestFrom(null, request.getParams(), request.getContentStreams());
+ req.getContext().put(PATH, path);
SolrQueryResponse resp = new SolrQueryResponse();
handler.handleRequest(req, resp);
checkForExceptions(resp);
diff --git a/solr/core/src/test/org/apache/solr/client/solrj/embedded/TestEmbeddedSolrServerAdminHandler.java b/solr/core/src/test/org/apache/solr/client/solrj/embedded/TestEmbeddedSolrServerAdminHandler.java
new file mode 100644
index 00000000000..84ecedfa7d5
--- /dev/null
+++ b/solr/core/src/test/org/apache/solr/client/solrj/embedded/TestEmbeddedSolrServerAdminHandler.java
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.client.solrj.embedded;
+
+import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Collection;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.client.solrj.SolrClient;
+import org.apache.solr.client.solrj.SolrRequest;
+import org.apache.solr.client.solrj.SolrServerException;
+import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
+import org.apache.solr.client.solrj.response.QueryResponse;
+import org.apache.solr.common.params.ModifiableSolrParams;
+import org.apache.solr.common.params.SolrParams;
+import org.apache.solr.common.util.ContentStream;
+import org.apache.solr.common.util.NamedList;
+import org.apache.solr.core.NodeConfig;
+import org.apache.solr.core.SolrResourceLoader;
+import org.junit.Test;
+
+public class TestEmbeddedSolrServerAdminHandler extends SolrTestCaseJ4 {
+
+ @Test
+ public void testPathIsAddedToContext() throws IOException, SolrServerException {
+ final Path path = createTempDir();
+
+ final SolrResourceLoader loader = new SolrResourceLoader(path);
+ final NodeConfig config = new NodeConfig.NodeConfigBuilder("testnode", loader)
+ .setConfigSetBaseDirectory(Paths.get(TEST_HOME()).resolve("configsets").toString())
+ .build();
+
+ try (final EmbeddedSolrServer server = new EmbeddedSolrServer(config, "collection1")) {
+ final SystemInfoRequest info = new SystemInfoRequest();
+ final NamedList response = server.request(info);
+ assertTrue(response.size() > 0);
+ }
+ }
+
+ private static class SystemInfoRequest extends SolrRequest<QueryResponse> {
+
+ public SystemInfoRequest() {
+ super(METHOD.GET, "/admin/info/system");
+ }
+
+ @Override
+ public SolrParams getParams() {
+ return new ModifiableSolrParams();
+ }
+
+ @Override
+ public Collection<ContentStream> getContentStreams() throws IOException {
+ return null;
+ }
+
+ @Override
+ protected QueryResponse createResponse(final SolrClient client) {
+ return new QueryResponse();
+ }
+ }
+
+}