Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nullpointer when multiple bindings are provided #1130

Open
amanteaux opened this issue Dec 2, 2024 · 5 comments
Open

Nullpointer when multiple bindings are provided #1130

amanteaux opened this issue Dec 2, 2024 · 5 comments

Comments

@amanteaux
Copy link

Using the latest version of Jersey-HK2, I have the following error when using an AbstractBinder:

WARNING: The following warnings have been detected: WARNING: HK2 failure has been detected in a code that does not run in an active Jersey Error scope.
WARNING: Unknown HK2 failure detected:
MultiException stack 1 of 1
java.lang.NullPointerException: Cannot invoke "org.glassfish.jersey.server.internal.process.RequestProcessingContext.request()" because the return value of "org.glassfish.jersey.server.internal.process.RequestProcessingContextReference.get()" is null
	at org.glassfish.jersey.server.internal.process.RequestProcessingConfigurator$ContainerRequestFactory.get(RequestProcessingConfigurator.java:67)
	at org.glassfish.jersey.server.internal.process.RequestProcessingConfigurator$ContainerRequestFactory.get(RequestProcessingConfigurator.java:56)
	at org.glassfish.jersey.inject.hk2.SupplierFactoryBridge.provide(SupplierFactoryBridge.java:76)
	at org.jvnet.hk2.internal.FactoryCreator.create(FactoryCreator.java:129)
[...]

I was able to reproduce a minimal example in this repository https://github.com/amanteaux/jersey-grizzly-hk2-issue (starting from https://github.com/eclipse-ee4j/jersey/tree/3.1.9/examples/helloworld)
It is not very clear what triggers the error, using the exact binding described in my sample project triggers the error (but if the order changes or if a binding is deleted, the error disappeared).

I suspect the error is from HK2, but it could be Jersey as well.

Here are the bindings:

bindFactory(SessionFactory2.class).to(Session2.class).in(RequestScoped.class);
bindFactory(SessionFactory.class).to(InterfaceSession.class).in(RequestScoped.class);
bindFactory(SessionFactory.class).to(Session.class).in(RequestScoped.class);

Here is the factory:

public class SessionFactory implements Factory<Session> {
    private final ContainerRequestContext context;

    @Inject
    public SessionFactory(ContainerRequestContext context) {
        this.context = context;
    }

    @Override
    public Session provide() {
        return new Session(context.getHeaderString("Custom-Code"));
    }

    @Override
    public void dispose(Session instance) {

    }
}

Here is the resource definition:

@Path("helloworld")
public class HelloWorldResource {
    @GET
    @Path("/sample-response")
    public String sampleResponse(@Context Session session) {
        return "hello " + session.code();
    }

    @POST
    @Path("/no-answer")
    public void noAnswer(@Context Session session) {
        System.out.println("no answer executed: " + session.code());
    }
}
@pzygielo
Copy link
Contributor

pzygielo commented Dec 3, 2024

@senivam Could you help to determine if there is something to be updated in HK2, Jersey or the reproducer, please?

@senivam
Copy link

senivam commented Dec 3, 2024

I'm looking into it. Probably, it's not directly related to the DefaultExceptionMapper introduced in the 3.1.x Jersey, but it should be some configuration issue because in 3.0.16 it works as is with the same HK2 version, and in 2.45 it works as well. I will look into it more.

@amanteaux
Copy link
Author

amanteaux commented Jan 14, 2025

Hello @senivam, have you been able to identify where the issue comes from?
Thank you for your help!

@senivam
Copy link

senivam commented Jan 14, 2025

Hello @amanteaux, unfortunately not yet. However, I'm still investigating. Hopefully, I will find the reason.

@amanteaux
Copy link
Author

Thank you for the update! I wish you luck to find the root issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants