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/10/30 13:27:00 UTC

[jira] [Created] (GROOVY-9802) groovy json - Unable to load FastStringService with java 11 http client

Matias Bjarland created GROOVY-9802:
---------------------------------------

             Summary: 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


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 out this line will make the code break 

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. 

 



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