users@glassfish.java.net

Re: Jersey NullPointerException (one in a series)

From: Paul Sandoz <Paul.Sandoz_at_oracle.com>
Date: Tue, 5 Oct 2010 11:18:59 +0200

On Sep 28, 2010, at 7:53 PM, glassfish_at_javadesktop.org wrote:

> https://glassfish.dev.java.net/issues/show_bug.cgi?id=13650
>
> This looks to be related to issue 13572 (https://glassfish.dev.java.net/issues/show_bug.cgi?id=13572
> ), where I laboriously put together three test cases to show at
> least two different injection problems in Jersey. However, in that
> case, simply adding @ManagedBean to the resource and ensuring that
> META-INF/beans.xml was not present solved the problem.
>

I think issue 13572 (the CDI NPE with Jersey) is unrelated to issue
13650.

Issue 13650 seems to be a bug in the EJB container. Jersey is
registering an EJB interceptor so it can perform injection on to the
EJB instances. But that registration is failing with:

Caused by: java.lang.NullPointerException

       at
com
.sun
.enterprise
.container
.common
.impl
.managedbean
.ManagedBeanManagerImpl
.registerRuntimeInterceptor(ManagedBeanManagerImpl.java:325)

       at
com
.sun
.ejb
.containers
.InternalInterceptorBindingImpl
.registerInterceptor(InternalInterceptorBindingImpl.java:110)

       ... 38 more

The relevant code is here:

     public static void initialize(ResourceConfig rc) {
         try {
             InitialContext ic =
InitialContextHelper.getInitialContext();
             if (ic == null) {
                 return;
             }
             Object interceptorBinder = ic.
                      
lookup("java:org.glassfish.ejb.container.interceptor_binding_spi");
             // Some implementations of InitialContext return null
instead of
             // throwing NamingException if there is no Object
associated with
             // the name
             if (interceptorBinder == null) {
                 LOGGER.config("The EJB interceptor binding API is not
available. JAX-RS EJB support is disabled.");
                 return;
             }

             Method interceptorBinderMethod =
interceptorBinder.getClass().
                     getMethod("registerInterceptor",
java.lang.Object.class);

             EJBInjectionInterceptor interceptor = new
EJBInjectionInterceptor();

             try {
                 interceptorBinderMethod.invoke(interceptorBinder,
interceptor); // <-- Fails here
             } catch (Exception ex) {
                 LOGGER.log(Level.SEVERE, "Error when configuring to
use the EJB interceptor binding API. JAX-RS EJB support is disabled.",
ex);
                 return;
             }


Paul.