groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alexander Astakhov (JIRA)" <j...@apache.org>
Subject [jira] [Created] (GROOVY-8478) JsonSlurper in 2.4 loses precision of big integers truncating them to longs
Date Tue, 13 Feb 2018 08:07:00 GMT
Alexander Astakhov created GROOVY-8478:
------------------------------------------

             Summary: JsonSlurper in 2.4 loses precision of big integers truncating them to
longs 
                 Key: GROOVY-8478
                 URL: https://issues.apache.org/jira/browse/GROOVY-8478
             Project: Groovy
          Issue Type: Bug
          Components: JSON
    Affects Versions: 2.4.13
            Reporter: Alexander Astakhov


Consider the following json string:

{{{"x":11819408672106971000}}}

When parsed by a JsonSlurper x value is trimmed to a -6627335401602580616 as a result of the
Long overflow.

The reason for this is the following code in the CharScanner.java starting from line 660:

 

{{final int length = index - from;}}

{{if (!foundDot && simple) {}}
{{  if (isInteger(buffer, from, length)) {}}
{{    value = parseIntFromTo(buffer, from, index);}}
{{  } else {}}
{{    value = parseLongFromTo(buffer, from, index);}}
{{  }}}
{{} else {}}
{{  value = parseBigDecimal(buffer, from, length);}}
{{}}}

Basically all the numbers besides ones in the scientific notation or containing dots are
treated as long at best.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message