eclipse-ee4j / jersey

Eclipse Jersey Project - Read our Wiki:
https://github.com/eclipse-ee4j/jersey/wiki
Other
691 stars 352 forks source link

NPE when using async from groovy with untyped closure #2882

Open jerseyrobot opened 10 years ago

jerseyrobot 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]

jerseyrobot commented 6 years ago
jerseyrobot commented 10 years ago

@glassfishrobot Commented Reported by simon_buettner

jerseyrobot commented 10 years ago

@glassfishrobot Commented @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.

jerseyrobot commented 8 years ago

@glassfishrobot Commented 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.

jerseyrobot commented 7 years ago

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