2 Replies Latest reply on May 18, 2009 2:59 AM by andyredhead

    JndiUtil - assumes HA-JNDI service is installed

    andyredhead

      Hi,

      in JBoss AS 4.2.3 the code for org.jboss.ejb3.JndiUtil includes:

       Object object = null;
      
       try
       {
       object = jndiContext.lookup(binding);
       }
       catch (NameNotFoundException e)
       {
       Context haCtx = InitialContextFactory.getHAContext(jndiContext);
       object = haCtx.lookup(binding);
       }
      
       return object;
       }
      


      So, if the local lookup fails, a call is made to the HA context - without checking to see if the haCtx object is not null...

      If the HA JNDI service is not installed (i.e. such as in my development environment) then this call fails with a null pointer exception.

      I stumbled upon this when I tried to configure an XML based entity manager injection into a stateless session bean and got the persistence-context-ref-name value wrong. I then had to install the ha jndi service (along with the default partition service) to find out what the actual name being looked up was.

      I thing it would be helpful if there was a not-null check on haCtx, if haCtx is null then the original naming exception should be re-thrown so the logs show what jndi name failed.

      Cheers,

      Andy

        • 1. Re: JndiUtil - assumes HA-JNDI service is installed
          jaikiran

          You haven't posted the exception stacktrace, so i can't say for sure - but I remember that there was a bug where if the jndi name used for injection was incorrect, then instead of a NameNotFoundException, this NullPointerException was being raised from the JndiUtil. This bug was fixed in AS 5.0.

          P.S: No matter what search term i try, i am not able to find the JIRA number for this.

          • 2. Re: JndiUtil - assumes HA-JNDI service is installed
            andyredhead

            Hi,

            sorry, no I didn't post the stack trace (though the position of the null object reference was clear).

            There isn't an entry in JIRA yet, I was holding off creating one until someone confirmed that I should do... would you like me to?

            The issue is definitely the assumption that the HA JNDI service will be running - if I install the HA JNDI service then that throws a NameNotFound and then I can see where I made my mistake.

            Cheers,

            Andy