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

Division by zero in StatsComponent with date field always missing

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 3.5
    • Fix Version/s: 3.6, 4.0-ALPHA
    • Component/s: None
    • Labels:
      None

      Description

      Using the StatsComponent with a date field that never has a value you'll get

      java.lang.ArithmeticException: / by zero at org.apache.solr.handler.component.DateStatsValues.addTypeSpecificStats (StatsValuesFactory.java:384)
      

      The problem is in this line of DateStatsValues:

      res.add("mean", new Date(sum / count));
      

      If count is 0 the division throws ArithmeticException because sum is long here. This doesn't happen with NumericStatsValues because sum is double there and the division result is Nan.
      By the way, the result of those divisions is not even included in the output when count is 0 because of this condition in SimpleStats#getStatsFields:

      if (isShard == true || (Long) stv.get("count") > 0) {
          res.add(f, stv);
      } else {
          res.add(f, null);
      }
      

      Therefore, it should never throw an exception!

        Attachments

        1. SOLR-3160.patch
          3 kB
          Luca Cavanna

          Activity

            People

            • Assignee:
              erickerickson Erick Erickson
              Reporter:
              lucacavanna Luca Cavanna
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: