Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-3894

NumberFormatException if value is too big

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.6.5
    • 1.6.6, 1.7-rc-1
    • None
    • None
    • Windows XP, Groovy 1.6.5

    Description

      We have an expression which can create values which are to big for BigDecimal.
      If the expression is printed out dircetly, it creates the value "Infinity" (Double.POSITIVE_INFINITY) which is fine.
      If expression is used as an assignment to a variable, a confusing NumberFormatException without a message text is created.

      Example:
      BigDecimal x = 999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
      println x ** 5 // ok, prints out "Infinity"
      BigDecimal y = x ** 5 // not ok, creates a NumberFormatException without a message text
      println y

      java.lang.NumberFormatException
      at java.math.BigDecimal.<init>(BigDecimal.java:455)
      at java.math.BigDecimal.<init>(BigDecimal.java:724)
      at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:284)
      at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.castToType(ScriptBytecodeAdapter.java:602)
      ...

      I suggest to check in DefaultTypeTransformation.castToType, line 284 for NaN and Infinity and create a NumberFormatException with a proper text like the Constructor BigDecimal (double val) does.

      Attachments

        Activity

          People

            roshandawrani Roshan Dawrani
            uwe.kirsch Uwe Kirsch
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: