Uploaded image for project: 'Commons Lang'
  1. Commons Lang
  2. LANG-1527

NumberUtils.createBigDecimal has a redundant argument check

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 3.10
    • Component/s: lang.math.*
    • Labels:
      None

      Description

      NumberUtils.createBigDecimal(String) has an argument check
      `str.trim().startsWith("--")`, which was added almost 20 years ago to
      handle a bug in JDK at that time. The corresponding check is already
      in place in nowadays' JDK and this check is redundant.

      public static BigDecimal createBigDecimal(final String str) {
          if (str == null) {
              return null;
          }
          // handle JDK1.3.1 bug where "" throws IndexOutOfBoundsException
          if (StringUtils.isBlank(str)) {
              throw new NumberFormatException("A blank string is not a valid number");
          }
          if (str.trim().startsWith("--")) {
              // this is protection for poorness in java.lang.BigDecimal.
              // it accepts this as a legal value, but it does not appear
              // to be in specification of class. OS X Java parses it to
              // a wrong value.
              throw new NumberFormatException(str + " is not a valid number.");
          }
          return new BigDecimal(str);
      }
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                prodigysov Pengyu Nie
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 20m
                  20m