[ https://issues.apache.org/jira/browse/SOLR-5400?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Noble Paul resolved SOLR-5400. ------------------------------ Resolution: Fixed Assignee: Noble Paul committed > NullPointerException > --------------------- > > Key: SOLR-5400 > URL: https://issues.apache.org/jira/browse/SOLR-5400 > Project: Solr > Issue Type: Bug > Affects Versions: 4.5 > Reporter: Pascal Chollet > Assignee: Noble Paul > Priority: Minor > > I want write tests for some of our own components which internally use a > SolrCore. As SolrCore is defined final, I cannot mock it and instead have to > create an instance of it. Therefore I came across the following constructor: > {code}public SolrCore(String name, CoreDescriptor cd) { > this.setName(name); > coreDescriptor = cd; > this.schema = null; > this.dataDir = null; > this.solrConfig = null; > this.startTime = System.currentTimeMillis(); > this.maxWarmingSearchers = 2; // we don't have a config yet, just pick a > number. > this.resourceLoader = null; > this.updateHandler = null; > this.isReloaded = true; > this.reqHandlers = null; > this.searchComponents = null; > this.updateProcessorChains = null; > this.infoRegistry = null; > this.codec = null; > solrCoreState = null; > } > {code} > When calling this constructor there will always be a NullPointerException, > because of the call of setName(...) before coreDescriptor is set. In setName > this.coreDescriptor (which was not yet set) is being used: > {code} > public void setName(String v) { > this.name = v; > this.logid = (v==null)?"":("["+v+"] "); > this.coreDescriptor = new CoreDescriptor(v, this.coreDescriptor); > } > {code} > The fix probably is to set the coreDesciptor first and then call setName. -- This message was sent by Atlassian JIRA (v6.1#6144) --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@lucene.apache.org For additional commands, e-mail: dev-h...@lucene.apache.org