Uploaded image for project: 'Commons JEXL'
  1. Commons JEXL
  2. JEXL-325

Potential race-condition in NumberParser.toString()

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 3.1
    • 3.2
    • None

    Description

      To format BigDecimal values the current implementation uses static instance of DecimalFormat class without synchronization, whereas according to Java doc Decimal formats are not synchronized and must be synchronized externally. There is also a dead branch on BigDecimal check. The suggestion is to change NumberParser.to String() to something as follows:

          @Override
          public String toString() {
              if (literal == null || clazz == null || Double.isNaN(literal.doubleValue())) {
                  return "NaN";
              }
              if (BigDecimal.class.equals(clazz)) {
                  synchronized (BIGDF) {
                      return BIGDF.format(literal);
                  }
              }
              StringBuilder strb = new StringBuilder(literal.toString());
              if (Float.class.equals(clazz)) {
                  strb.append('f');
              } else if (Double.class.equals(clazz)) {
                  strb.append('d');
              } else if (BigInteger.class.equals(clazz)) {
                  strb.append('h');
              } else if (Long.class.equals(clazz)) {
                  strb.append('l');
              }
              return strb.toString();
          }
      

      Attachments

        Activity

          People

            henrib Henri Biestro
            dmitri_blinov Dmitri Blinov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: