Skip to content

Apache Lucene open-source search software

SOLR-9534: Fix test failures related to nullpointer when printing core name in logs.

Jan Høydahlbede7aefa3b2
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 4bf25aa99b4..d310ff23c71 100644
--- a/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java
+++ b/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java
@@ -198,14 +198,23 @@ public class SolrResourceLoader implements ResourceLoader,Closeable
if (newLoader != classLoader) {
this.classLoader = newLoader;
}
+
log.info("[{}] Added {} libs to classloader, from paths: {}",
- getCoreProperties().getProperty(SOLR_CORE_NAME), urls.size(), urls.stream()
+ getCoreName("null"), urls.size(), urls.stream()
.map(u -> u.getPath().substring(0,u.getPath().lastIndexOf("/")))
.sorted()
.distinct()
.collect(Collectors.toList()));
}
+ private String getCoreName(String defaultVal) {
+ if (getCoreProperties() != null) {
+ return getCoreProperties().getProperty(SOLR_CORE_NAME, defaultVal);
+ } else {
+ return defaultVal;
+ }
+ }
+
/**
* Adds URLs to the ResourceLoader's internal classloader. This method <b>MUST</b>
* only be called prior to using this ResourceLoader to get any resources, otherwise
diff --git a/solr/core/src/java/org/apache/solr/schema/IndexSchema.java b/solr/core/src/java/org/apache/solr/schema/IndexSchema.java
index 96ad09dc0a4..63c82ef17a6 100644
--- a/solr/core/src/java/org/apache/solr/schema/IndexSchema.java
+++ b/solr/core/src/java/org/apache/solr/schema/IndexSchema.java
@@ -462,14 +462,11 @@ public class IndexSchema {
final XPath xpath = schemaConf.getXPath();
String expression = stepsToPath(SCHEMA, AT + NAME);
Node nd = (Node) xpath.evaluate(expression, document, XPathConstants.NODE);
+ String coreName = getCoreName("null");
StringBuilder sb = new StringBuilder();
// Another case where the initialization from the test harness is different than the "real world"
sb.append("[");
- if (loader.getCoreProperties() != null) {
- sb.append(loader.getCoreProperties().getProperty(SOLR_CORE_NAME));
- } else {
- sb.append("null");
- }
+ sb.append(coreName);
sb.append("] ");
if (nd==null) {
sb.append("schema has no name!");
@@ -538,7 +535,7 @@ public class IndexSchema {
}
}
log.info("[{}] default search field in schema is {}. WARNING: Deprecated, please use 'df' on request instead.",
- loader.getCoreProperties().getProperty(SOLR_CORE_NAME), defaultSearchFieldName);
+ coreName, defaultSearchFieldName);
}
// /schema/solrQueryParser/@defaultOperator
@@ -550,7 +547,7 @@ public class IndexSchema {
isExplicitQueryParserDefaultOperator = true;
queryParserDefaultOperator=node.getNodeValue().trim();
log.info("[{}] query parser default operator is {}. WARNING: Deprecated, please use 'q.op' on request instead.",
- loader.getCoreProperties().getProperty(SOLR_CORE_NAME), queryParserDefaultOperator);
+ coreName, queryParserDefaultOperator);
}
// /schema/uniqueKey/text()
@@ -580,7 +577,7 @@ public class IndexSchema {
uniqueKeyFieldName=uniqueKeyField.getName();
uniqueKeyFieldType=uniqueKeyField.getType();
log.info("[{}] unique key field: {}",
- loader.getCoreProperties().getProperty(SOLR_CORE_NAME), uniqueKeyFieldName);
+ coreName, uniqueKeyFieldName);
// Unless the uniqueKeyField is marked 'required=false' then make sure it exists
if( Boolean.FALSE != explicitRequiredProp.get( uniqueKeyFieldName ) ) {
@@ -610,7 +607,15 @@ public class IndexSchema {
// create the field analyzers
refreshAnalyzers();
}
-
+
+ private String getCoreName(String defaultVal) {
+ if (loader != null && loader.getCoreProperties() != null) {
+ return loader.getCoreProperties().getProperty(SOLR_CORE_NAME, defaultVal);
+ } else {
+ return defaultVal;
+ }
+ }
+
protected void postReadInform() {
//Run the callbacks on SchemaAware now that everything else is done
for (SchemaAware aware : schemaAware) {