javaee / jersey

This is no longer the active Jersey repository. Please see the README.md
http://jersey.github.io
Other
2.86k stars 2.35k forks source link

NPE when using async from groovy with untyped closure #2882

Open glassfishrobot opened 10 years ago

glassfishrobot commented 10 years ago

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<Object>() {
    @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]

glassfishrobot commented 10 years ago

Reported by simon_buettner

glassfishrobot commented 10 years ago

@AdamLindenthal said: Hi Simon, thanks for reporting this, I am moving the issue to our backlog, so that we can plan it for one of the future sprints.

glassfishrobot commented 8 years ago

svavra said: Triaged. Lets check if this is still reproducible; otherwise, it will be closed. Sorry for the delay. Please do not hesitate to contribute to this by submitting your own pull request on Github.

glassfishrobot commented 7 years ago

This issue was imported from java.net JIRA JERSEY-2610