You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Matias Bjarland (Jira)" <ji...@apache.org> on 2020/11/02 09:43:00 UTC
[jira] [Updated] (GROOVY-9802) groovy json - Unable to load
FastStringService with java 11 http client
[ https://issues.apache.org/jira/browse/GROOVY-9802?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Matias Bjarland updated GROOVY-9802:
------------------------------------
Description:
The following code:
{code:java}
import groovy.json.*
import java.net.http.*
import static java.net.http.HttpResponse.*
def req = HttpRequest.newBuilder()
.uri(URI.create('https://jsonplaceholder.typicode.com/todos/1'))
.build()
def parser = new JsonSlurper()
// parser.parseText('{}') // <--- commenting in this line will make the code work
def res = HttpClient.newHttpClient().sendAsync(req, BodyHandlers.ofString())
.thenApply(r -> r.body())
.thenApply(parser::parseText)
.join()
println "response: $res"
{code}
when run, will break with the following exception:
{noformat}
─➤ groovy queryjson.groovy
Caught: java.util.concurrent.CompletionException: java.lang.RuntimeException: Unable to load FastStringService
java.util.concurrent.CompletionException: java.lang.RuntimeException: Unable to load FastStringService
Caused by: java.lang.RuntimeException: Unable to load FastStringService
at org.apache.groovy.json.internal.FastStringUtils.getService(FastStringUtils.java:56)
at org.apache.groovy.json.internal.FastStringUtils.toCharArray(FastStringUtils.java:66)
at org.apache.groovy.json.internal.BaseJsonParser.parse(BaseJsonParser.java:113)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at com.sun.proxy.$Proxy17.apply(Unknown Source)
{noformat}
commenting in the indicated line will make the code work.
I assume this is caused by the fact that the `thenApply` block of code is run from a different (pooled) thread and from a different classloader context.
I get this, but in my mind having this simple example break is bad ergonomics and with the ubiquity of json APIs and the inclusion of a decent http client in java 11 I would expect this pattern to become quite common. I.e. wanting to create a no-deps groovy script / class which makes an http call and parses the returned json.
was:
The following code:
{code:java}
import groovy.json.*
import java.net.http.*
import static java.net.http.HttpResponse.*
def req = HttpRequest.newBuilder()
.uri(URI.create('https://jsonplaceholder.typicode.com/todos/1'))
.build()
def parser = new JsonSlurper()
// parser.parseText('{}') // <--- commenting in this line will make the code work
def res = HttpClient.newHttpClient().sendAsync(req, BodyHandlers.ofString())
.thenApply(r -> r.body())
.thenApply(parser::parseText)
.join()
println "response: $res"
{code}
when run, will break with the following exception:
{noformat}
─➤ groovy queryjson.groovy
Caught: java.util.concurrent.CompletionException: java.lang.RuntimeException: Unable to load FastStringService
java.util.concurrent.CompletionException: java.lang.RuntimeException: Unable to load FastStringService
Caused by: java.lang.RuntimeException: Unable to load FastStringService
at org.apache.groovy.json.internal.FastStringUtils.getService(FastStringUtils.java:56)
at org.apache.groovy.json.internal.FastStringUtils.toCharArray(FastStringUtils.java:66)
at org.apache.groovy.json.internal.BaseJsonParser.parse(BaseJsonParser.java:113)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at com.sun.proxy.$Proxy17.apply(Unknown Source)
{noformat}
commenting in the indicated line will make the code work.
I assume this is caused by the fact that the `thenApply` block of code is run from a different (pooled) thread and from a different classloader context. I get this, but in my mind having this simple example break is not great ergonomics for groovy.
> groovy json - Unable to load FastStringService with java 11 http client
> ------------------------------------------------------------------------
>
> Key: GROOVY-9802
> URL: https://issues.apache.org/jira/browse/GROOVY-9802
> Project: Groovy
> Issue Type: Bug
> Components: JSON
> Affects Versions: 3.0.6
> Environment: Groovy Version: 3.0.6 JVM: 11.0.9 Vendor: Amazon.com Inc. OS: Linux
> Reporter: Matias Bjarland
> Priority: Major
>
> The following code:
> {code:java}
> import groovy.json.*
> import java.net.http.*
> import static java.net.http.HttpResponse.*
> def req = HttpRequest.newBuilder()
> .uri(URI.create('https://jsonplaceholder.typicode.com/todos/1'))
> .build()
> def parser = new JsonSlurper()
> // parser.parseText('{}') // <--- commenting in this line will make the code work
> def res = HttpClient.newHttpClient().sendAsync(req, BodyHandlers.ofString())
> .thenApply(r -> r.body())
> .thenApply(parser::parseText)
> .join()
> println "response: $res"
> {code}
> when run, will break with the following exception:
> {noformat}
> ─➤ groovy queryjson.groovy
> Caught: java.util.concurrent.CompletionException: java.lang.RuntimeException: Unable to load FastStringService
> java.util.concurrent.CompletionException: java.lang.RuntimeException: Unable to load FastStringService
> Caused by: java.lang.RuntimeException: Unable to load FastStringService
> at org.apache.groovy.json.internal.FastStringUtils.getService(FastStringUtils.java:56)
> at org.apache.groovy.json.internal.FastStringUtils.toCharArray(FastStringUtils.java:66)
> at org.apache.groovy.json.internal.BaseJsonParser.parse(BaseJsonParser.java:113)
> at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at com.sun.proxy.$Proxy17.apply(Unknown Source)
> {noformat}
> commenting in the indicated line will make the code work.
> I assume this is caused by the fact that the `thenApply` block of code is run from a different (pooled) thread and from a different classloader context.
> I get this, but in my mind having this simple example break is bad ergonomics and with the ubiquity of json APIs and the inclusion of a decent http client in java 11 I would expect this pattern to become quite common. I.e. wanting to create a no-deps groovy script / class which makes an http call and parses the returned json.
>
--
This message was sent by Atlassian Jira
(v8.3.4#803005)