[jira] [Commented] (GROOVY-9401) JsonOutput.prettyPrint generates string with null bytes on OpenJ9 JVM

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[jira] [Commented] (GROOVY-9401) JsonOutput.prettyPrint generates string with null bytes on OpenJ9 JVM

Paul King (Jira)

    [ https://issues.apache.org/jira/browse/GROOVY-9401?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17037889#comment-17037889 ]

Giovanni Pardini commented on GROOVY-9401:
------------------------------------------

I was able to track the bug down to method {{DirectFastStringService.toCharArray}} which is called with parameter "123" and returns the following 16-byte array:

{code}
0 = '1' 49
1 = '2' 50
2 = '3' 51
3 = '\u0000' 0
4 = '\u0000' 0
5 = '\u0000' 0
6 = '\u0000' 0
7 = '\u0000' 0
8 = '\u0000' 0
9 = '\u0000' 0
10 = '\u0000' 0
11 = '\u0000' 0
12 = '\u0000' 0
13 = '\u0000' 0
14 = '\u0000' 0
15 = '\u0000' 0
{code}

The entire array is then concatenated to the current buffer to produce the resulting JSON string.

Here is the stack trace:
{code}
toCharArray:34, DirectFastStringService (org.apache.groovy.jsondirect)
toCharArray:67, FastStringUtils (org.apache.groovy.json.internal)
addString:107, CharBuf (org.apache.groovy.json.internal)
prettyPrint:220, JsonOutput (groovy.json)
main:10, GroovyBug9401 (it.prdmx.bugs)
invoke0:-1, NativeMethodAccessorImpl (sun.reflect)
invoke:62, NativeMethodAccessorImpl (sun.reflect)
invoke:43, DelegatingMethodAccessorImpl (sun.reflect)
invoke:498, Method (java.lang.reflect)
invoke:101, CachedMethod (org.codehaus.groovy.reflection)
doMethodInvoke:323, MetaMethod (groovy.lang)
invokeStaticMethod:1470, MetaClassImpl (groovy.lang)
invokeMethod:985, InvokerHelper (org.codehaus.groovy.runtime)
runScriptOrMainOrTestOrRunnable:275, GroovyShell (groovy.lang)
run:376, GroovyShell (groovy.lang)
run:365, GroovyShell (groovy.lang)
processOnce:592, GroovyMain (groovy.ui)
run:336, GroovyMain (groovy.ui)
access$1400:69, GroovyMain (groovy.ui)
process:295, GroovyMain$GroovyCommand (groovy.ui)
processArgs:134, GroovyMain (groovy.ui)
main:116, GroovyMain (groovy.ui)
invoke0:-1, NativeMethodAccessorImpl (sun.reflect)
invoke:62, NativeMethodAccessorImpl (sun.reflect)
invoke:43, DelegatingMethodAccessorImpl (sun.reflect)
invoke:498, Method (java.lang.reflect)
rootLoader:110, GroovyStarter (org.codehaus.groovy.tools)
main:128, GroovyStarter (org.codehaus.groovy.tools)
{code}

> JsonOutput.prettyPrint generates string with null bytes on OpenJ9 JVM
> ---------------------------------------------------------------------
>
>                 Key: GROOVY-9401
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9401
>             Project: Groovy
>          Issue Type: Bug
>          Components: JSON
>    Affects Versions: 2.5.9
>         Environment: Ubuntu 18.04.4 LTS
> JVM
> DEB package: adoptopenjdk-8-openj9 8u242-b08.openj9-0.18.1-2
> openjdk version "1.8.0_242"
> OpenJDK Runtime Environment (build 1.8.0_242-b08)
> Eclipse OpenJ9 VM (build openj9-0.18.1, JRE 1.8.0 Linux amd64-64-Bit Compressed References 20200122_511 (JIT enabled, AOT enabled)
> OpenJ9   - 51a5857d2
> OMR      - 7a1b0239a
> JCL      - 8cf8a30581 based on jdk8u242-b08)
>            Reporter: Giovanni Pardini
>            Priority: Major
>             Fix For: 3.0.0
>
>
> Using OpenJDK with Eclipse OpenJ9 JVM from [https://adoptopenjdk.net/,] the method JsonOutput.prettyPrint() generates a string which contains null bytes.
> h3. {{TEST CODE}}
> {code:groovy}
> import groovy.json.JsonOutput
> String s = JsonOutput.prettyPrint('{"id":123}')
> println s.getBytes().encodeHex().toString()
> println s
> {code}
> h3. {{OUTPUT}}
> {code}
> 7b0a20202020226964223a20313233000000000000000000000000000a7d
> {
>     "id": 123
> }
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)