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

This commit is contained in:
Jan Høydahl 2016-09-22 23:31:28 +02:00
parent 73c2edddf0
commit bede7aefa3
2 changed files with 24 additions and 10 deletions

View File

@ -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

View File

@ -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) {