eclipse-ee4j / eclipse-ee4j/jersey

NPE when using async from groovy with untyped closure

Open
#2,882 5 comments 0 reactions 0 assignees View on GitHub
Component: core Priority: Major Type: Bug
Dominant language
Java
Stars
730
Forks
382
PR merge metrics
No merged PRs in 30d

Description

When trying to issue a post using the async method a NullPointerException is thrown by the JerseyInvocation class. Here is an example groovy script which show the issue. It can be executed right away. All dependencies will be resolved by your groovy installation.

```
@Grapes([
@Grab(group='org.glassfish.jersey.core', module='jersey-client', version='2.11'),
@Grab(group='com.google.guava', module='guava', version='17.0')
])
import javax.ws.rs.client.Client
import javax.ws.rs.client.ClientBuilder
import javax.ws.rs.client.InvocationCallback
import javax.ws.rs.client.WebTarget
import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors
import com.google.common.util.concurrent.JdkFutureAdapters

Client client = ClientBuilder.newBuilder().build()
WebTarget webTarget = client.target('https://api.mailgun.net/v2/samples.mailgun.org/messages')
/**
* Fails to execute request.
*
* here: /org/glassfish/jersey/client/JerseyInvocation.java
* Line: 867
* Reason: ReflectionHelper.getParameterizedTypeArguments(pair) returns null for groovy closure
*/
def call1 = webTarget.request().async().post(null, [
completed: { Object response -> println response },
failed: { Throwable t -> System.err.println(t) }
] as InvocationCallback)

/**
* Executes request (but fails due to authorization issues, not relevant here)
*/
def call2 = webTarget.request().async().post(null, new InvocationCallback() {
@Override
void completed(Object o) {
println o
}

@Override
void failed(Throwable throwable) {
System.err.println(throwable)
}
})

ExecutorService executorService = Executors.newSingleThreadExecutor()
def listenableCall1 = JdkFutureAdapters.listenInPoolThread(call1, executorService)
listenableCall1.addListener({ }, executorService)

def listenableCall2 = JdkFutureAdapters.listenInPoolThread(call2, executorService)
listenableCall2.addListener({
client.close()
executorService.shutdown()
}, executorService)
```
#### Environment
JDK 7
#### Affected Versions
[2.11]

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.