Thanks to visit codestin.com
Credit goes to github.com

Skip to content

BiggerDecimal.parseBiggerDecimalUnsafe throws NumberFormatException #2132

@usommerl

Description

@usommerl

I ran into a NumberFormatException when trying to decode user-provided strings as double values with circe v0.14.5:

val userInput = """"E7""""
io.circe.parser.parse(userInput).flatMap(_.as[Double]) // java.lang.NumberFormatException: Zero length BigInteger

The actual culprit is BiggerDecimal.parseBiggerDecimalUnsafe which is used by several decoders. The behaviour of this method has changed between releases v0.14.2 and v0.14.3 (regardless of the Scala version):

v0.14.2

echo 'print(io.circe.numbers.BiggerDecimal.parseBiggerDecimalUnsafe("E7"))' \
       | scala-cli -S 3.2.2 -q --dependency "io.circe::circe-core::0.14.2" _.sc

null

v0.14.3

echo 'print(io.circe.numbers.BiggerDecimal.parseBiggerDecimalUnsafe("E7"))' \
       | scala-cli -S 3.2.2 -q --dependency "io.circe::circe-core::0.14.3" _.sc

Exception in thread "main" java.lang.ExceptionInInitializerError
	at stdin_sc$.main(stdin:17)
	at stdin_sc.main(stdin)
Caused by: java.lang.NumberFormatException: Zero length BigInteger
	at java.base/java.math.BigInteger.<init>(BigInteger.java:484)
	at java.base/java.math.BigInteger.<init>(BigInteger.java:672)
	at io.circe.numbers.BiggerDecimal$.parseBiggerDecimalUnsafe(BiggerDecimal.scala:359)
	at stdin$.<clinit>(stdin:1)
	... 2 more

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions