Uploaded image for project: 'Solr'
  1. Solr
  2. SOLR-5526

Query parser extends standard cause NPE on Solr startup

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Blocker
    • Resolution: Fixed
    • 4.5.1, 4.6, 6.0
    • 4.7, 6.0
    • query parsers
    • None
    • Linux, Java 1.7.0_45

    Description

      Adding any custom query parser extending standard one with non-final field NAME lead to messy NullPointerException during Solr startup.

      Definition of standard parsers is located in QParserPlugin.standardPlugins static array. The array contains names from static NAME fields and classes for each plugin.

      But all of listed parsers are derived from QParserPlugin, so we have circular dependency of static fields.

      Normally, class loader start initializing QParserPlugin before all listed plugins in SolrCore.initQParsers, and array elements referenced to NAME plugins' fields are filled properly.

      Custom parsers are instantiated before standard parsers. And when we subclass plugin with non-final NAME field and add it to Solr via solrconfig.xml, class loader start loading our class before QParserPlugin. Because QParserPlugin is a superclass for plugin, it must be initialized before subclasses, and static dereferencing cause null elements in standardPlugins array because it filled before NAME field of loading plugin's superclass.

      How to reproduce:

      1. Checkout Solr (trunk or stable)
      2. Add the following line to solr/example/solr/collection1/conf/solrconfig.xml
        <queryParser name="fail" class="solr.search.LuceneQParserPlugin"/>
      3. Call ant run-example in solr folder

      Possible workarounds:

      • dev-workaround: add int workaround = QParserPlugin.standardPlugins.length; as a first line to
        SolrCore.initQParsers
      • user-workaround: add plugin with final NAME field (edismax) to solrconfig.xml before subclasses of standard plugins.
        <queryParser name="workaround" class="solr.search.ExtendedDismaxQParserPlugin"/>

      Possible fix:
      Move standardPlugins to new final class to break circular dependency.

      Attachments

        1. SOLR-5526-tests.patch
          7 kB
          Vitaliy Zhovtyuk
        2. SOLR-5526-final-names.patch
          13 kB
          Nikolay Khitrin
        3. SOLR-5526-final-names.patch
          12 kB
          Vitaliy Zhovtyuk
        4. SOLR-5526.patch
          9 kB
          Nikolay Khitrin
        5. SOLR-5526.patch
          20 kB
          Vitaliy Zhovtyuk
        6. SOLR-5526.patch
          22 kB
          Vitaliy Zhovtyuk
        7. SOLR-5526.patch
          23 kB
          Chris M. Hostetter
        8. SOLR-5526.patch
          23 kB
          Chris M. Hostetter
        9. NPE_load_trace
          3 kB
          Vitaliy Zhovtyuk

        Issue Links

          Activity

            People

              Unassigned Unassigned
              khitrin Nikolay Khitrin
              Votes:
              2 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: