You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by "Jack Krupansky (JIRA)" <ji...@apache.org> on 2013/02/09 18:37:12 UTC

[jira] [Created] (SOLR-4423) NPE in SolrParams.toSolrParams when an invalid datatype is used in an XML named list in solrconfig.xml

Jack Krupansky created SOLR-4423:
------------------------------------

             Summary: NPE in SolrParams.toSolrParams when an invalid datatype is used in an XML named list in solrconfig.xml
                 Key: SOLR-4423
                 URL: https://issues.apache.org/jira/browse/SOLR-4423
             Project: Solr
          Issue Type: Bug
          Components: Schema and Analysis
    Affects Versions: 4.0
            Reporter: Jack Krupansky


An NPE occurs in SolrParams.toSolrParams if an invalid datatype is used for an entry in an XML named list, such as for "defaults" in a request handler in solrconfig.xml.

Repro:

Add this snippet to the Solr 4.0 example solrconfig.xml:

{code}
  <requestHandler name="/testBug" class="solr.SearchHandler">
    <lst name="defaults">
      <string name="df">name</string>
    </lst>
  </requestHandler>
{code}

The user error there is using "string" instead of "str".

Now try to start Solr. This NPE occurs:

{code}
Feb 09, 2013 12:02:27 PM org.apache.solr.core.CoreContainer create
SEVERE: Unable to create core: collection1
java.lang.NullPointerException
        at org.apache.solr.common.params.SolrParams.toSolrParams(SolrParams.java:295)
        at org.apache.solr.handler.RequestHandlerBase.init(RequestHandlerBase.java:100)
        at org.apache.solr.handler.component.SearchHandler.init(SearchHandler.java:76)
        at org.apache.solr.core.RequestHandlers.initHandlersFromConfig(RequestHandlers.java:178)
        at org.apache.solr.core.SolrCore.<init>(SolrCore.java:657)
        at org.apache.solr.core.SolrCore.<init>(SolrCore.java:566)
        at org.apache.solr.core.CoreContainer.create(CoreContainer.java:850)
        at org.apache.solr.core.CoreContainer.load(CoreContainer.java:534)
        at org.apache.solr.core.CoreContainer.load(CoreContainer.java:356)
        at org.apache.solr.core.CoreContainer$Initializer.initialize(CoreContainer.java:308)
        at org.apache.solr.servlet.SolrDispatchFilter.init(SolrDispatchFilter.java:107)
{code}

The NPE is due to the fact that the element/parameter value is null at this line:

{code}
      String prev = map.put(params.getName(i), params.getVal(i).toString());
{code}

It is null because DOMUtil.addToNamedList leaves it null if the datatype is invalid:

{code}
    Object val=null;

    if ("lst".equals(type)) {
      ...
    } else {
      final String textValue = getText(nd);
      try {
        if ("str".equals(type)) {
          val = textValue;
        ...
        } else if ("bool".equals(type)) {
          val = StrUtils.parseBool(textValue);
        }
        // :NOTE: Unexpected Node names are ignored
        // :TODO: should we generate an error here?
      } catch (NumberFormatException nfe) {
        ...
      }
    }

    if (nlst != null) nlst.add(name,val);
    if (arr != null) arr.add(val);
{code}

The "NOTE" is incorrect in that the node is not "ignored" - it is in fact added to the list as shown, but with a null value, which causes problems later.

I suggest replacing the TODO (and NOTE) with an "else" that throws a readable exception such as "Named list type '" + type + "' is invalid for name '" + name + "'".


--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org