groovy

NumberFormatException if value is too big

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.6.5
  • Fix Version/s: 1.6.6, 1.7-rc-1
  • Component/s: None
  • Labels:
    None
  • Environment:
    Windows XP, Groovy 1.6.5
  • Testcase included:
    yes
  • Number of attachments :
    0

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.

Activity

Hide
Roshan Dawrani added a comment -

Fixed. It now fails with the following message

Caught: java.lang.NumberFormatException: Infinite or NaN
Show
Roshan Dawrani added a comment - Fixed. It now fails with the following message
Caught: java.lang.NumberFormatException: Infinite or NaN

People

Vote (0)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: