Commons Lang
  1. Commons Lang
  2. LANG-75

NumberUtils.createBigDecimal("") NPE in Sun 1.3.1_08

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.0
    • Component/s: None
    • Labels:
      None
    • Environment:

      Operating System: other
      Platform: Other

      Description

      Hello,

      The NumberUtils.createXXX methods all have the following pattern:

      public static XXX createXXX(String str) {
      if (str == null)

      { return null; }

      In the case of BigDecimal, passing in a "" to new BigDecimal(String) in Sun
      1.3.1_08 blows up like this:

      java.lang.StringIndexOutOfBoundsException: String index out of range: 0
      at java.lang.String.charAt(String.java:582)
      at java.math.BigDecimal.<init>(BigDecimal.java:124)
      at org.apache.commons.lang.math.NumberUtils.createBigDecimal(NumberUtils.java:4
      78)
      at org.apache.commons.lang.math.NumberUtilsTest.testCreateBigDecimal(NumberUtil
      sTest.java:209)

      Under Sun 1.4.2, you get a NumberFormatException if the length of the string is
      0 (no trim()). The unit tests expect a NumberFormatException when you pass in "".

      So... to make this all nice on 1.3, should all of the guard clauses become:

      (1)

      if (StringUtil.isEmpty(str)) { return null; }

      (2)

      if (StringUtil.isBlank(str))

      { return null; }

      (3)

      if (str == null) { return null; }

      if (StringUtil.isEmpty(str))

      { return str; }

      ?

      I think (2) would be good since it would not blow up on "" AND " " but I am not
      familiar with the various invocation contexts, so, please opine.

      Thanks,
      Gary

        Activity

        ggregory@seagullsw.com created issue -
        Henri Yandell made changes -
        Field Original Value New Value
        issue.field.bugzillaimportkey 21904 12340874
        Henri Yandell made changes -
        Key COM-723 LANG-75
        Affects Version/s Nightly Builds [ 12311648 ]
        Assignee Jakarta Commons Developers Mailing List [ commons-dev@jakarta.apache.org ]
        Component/s Lang [ 12311121 ]
        Fix Version/s 2.0 Final [ 12311658 ]
        Project Commons [ 12310458 ] Commons Lang [ 12310481 ]
        Henri Yandell made changes -
        Affects Version/s Nightly Builds [ 12311718 ]
        Henri Yandell made changes -
        Fix Version/s 2.0 Final [ 12311706 ]
        Mark Thomas made changes -
        Workflow jira [ 12369779 ] Default workflow, editable Closed status [ 12602459 ]
        Mark Thomas made changes -
        Reporter Gary Gregory [ ggregory@seagullsw.com ] Gary D. Gregory [ garydgregory ]
        Henri Yandell made changes -
        Affects Version/s Nightly Builds [ 12311718 ]

          People

          • Assignee:
            Unassigned
            Reporter:
            Gary Gregory
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development