You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Alexander Astakhov (JIRA)" <ji...@apache.org> on 2018/02/13 08:07:00 UTC

[jira] [Updated] (GROOVY-8478) JsonSlurper in 2.4 loses precision of big integers truncating them to longs

     [ https://issues.apache.org/jira/browse/GROOVY-8478?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Alexander Astakhov updated GROOVY-8478:
---------------------------------------
    Description: 
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.

  was:
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.


> 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
>            Priority: Major
>
> 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)