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

TrieTokenizerFactory should catch NumberFormatException, return 400 (not 500)

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 3.4, 4.0-ALPHA
    • 4.0-ALPHA
    • Schema and Analysis
    • None
    • 4.0 trunk, snapshot taken 09/08/2011.

    Description

      TrieTokenizerFactory is allowing bad user input to result in a 500 error rather than a 400. For a long-valued field, for example, this code in TrieTokenizerFactory.reset() will throw a NumberFormatException:

      > case LONG:
      > ts.setLongValue(Long.parseLong(v));
      > break;

      The NFE gets all the way out to RequestHandlerBase.handleRequest():

      > catch (Exception e) {
      > SolrException.log(SolrCore.log,e);
      > if (e instanceof ParseException)

      { > e = new SolrException(SolrException.ErrorCode.BAD_REQUEST, e); > }

      but is not caught here, and ends up coming out of SolrDispatchFilter.sendError as a 500.

      Simply catching NFE and turning it into a SolrException does the trick:

      ==== solr/core/src/java/org/apache/solr/analysis/TrieTokenizerFactory.java#1 - /4.0-trunk-09082011/solr/core/src/java/org/apache/solr/analysis/TrieTokenizerFactory.java ====
      110a111,112
      > } catch (NumberFormatException e) {
      > throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Unable to parse input", e);

      Attachments

        Activity

          People

            hossman Chris M. Hostetter
            jeffrey.crump@gmail.com Jeff Crump
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - 1h
                1h
                Remaining:
                Remaining Estimate - 1h
                1h
                Logged:
                Time Spent - Not Specified
                Not Specified