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) { if (newLoader != classLoader) {
this.classLoader = newLoader; this.classLoader = newLoader;
} }
log.info("[{}] Added {} libs to classloader, from paths: {}", 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("/"))) .map(u -> u.getPath().substring(0,u.getPath().lastIndexOf("/")))
.sorted() .sorted()
.distinct() .distinct()
.collect(Collectors.toList())); .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> * 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 * 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(); final XPath xpath = schemaConf.getXPath();
String expression = stepsToPath(SCHEMA, AT + NAME); String expression = stepsToPath(SCHEMA, AT + NAME);
Node nd = (Node) xpath.evaluate(expression, document, XPathConstants.NODE); Node nd = (Node) xpath.evaluate(expression, document, XPathConstants.NODE);
String coreName = getCoreName("null");
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
// Another case where the initialization from the test harness is different than the "real world" // Another case where the initialization from the test harness is different than the "real world"
sb.append("["); sb.append("[");
if (loader.getCoreProperties() != null) { sb.append(coreName);
sb.append(loader.getCoreProperties().getProperty(SOLR_CORE_NAME));
} else {
sb.append("null");
}
sb.append("] "); sb.append("] ");
if (nd==null) { if (nd==null) {
sb.append("schema has no name!"); 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.", 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 // /schema/solrQueryParser/@defaultOperator
@ -550,7 +547,7 @@ public class IndexSchema {
isExplicitQueryParserDefaultOperator = true; isExplicitQueryParserDefaultOperator = true;
queryParserDefaultOperator=node.getNodeValue().trim(); queryParserDefaultOperator=node.getNodeValue().trim();
log.info("[{}] query parser default operator is {}. WARNING: Deprecated, please use 'q.op' on request instead.", 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() // /schema/uniqueKey/text()
@ -580,7 +577,7 @@ public class IndexSchema {
uniqueKeyFieldName=uniqueKeyField.getName(); uniqueKeyFieldName=uniqueKeyField.getName();
uniqueKeyFieldType=uniqueKeyField.getType(); uniqueKeyFieldType=uniqueKeyField.getType();
log.info("[{}] unique key field: {}", 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 // Unless the uniqueKeyField is marked 'required=false' then make sure it exists
if( Boolean.FALSE != explicitRequiredProp.get( uniqueKeyFieldName ) ) { if( Boolean.FALSE != explicitRequiredProp.get( uniqueKeyFieldName ) ) {
@ -611,6 +608,14 @@ public class IndexSchema {
refreshAnalyzers(); 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() { protected void postReadInform() {
//Run the callbacks on SchemaAware now that everything else is done //Run the callbacks on SchemaAware now that everything else is done
for (SchemaAware aware : schemaAware) { for (SchemaAware aware : schemaAware) {