JNDI.lookup not handling unknown JNDI variables elegantly #141

Closed
wfsaxton opened this Issue Jun 30, 2015 · 8 comments

Projects

None yet

3 participants

@wfsaxton

It looks like the lookup method tries to be helpful by returning null for unknown JNDI variables:

try {
    context = new InitialContext();
    return (T) context.lookup(name);
} catch (NameNotFoundException e) {
    return null;
} catch (NamingException e) {
    throw new IllegalStateException(e);

But in my case, when I run the following:

# swr/devLoginEnabled is undefined
Boolean devLoginEnabled = JNDI.lookup("swr/devLoginEnabled");

I get:
java.lang.IllegalStateException: javax.naming.NamingException: Lookup failed for 'swr/devLoginEnabled' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NameNotFoundException: devLoginEnabled not found]
at org.omnifaces.util.JNDI.lookup(JNDI.java:92)

Shouldn't JNDI.lookup be returning null if the JNDI variable does not exist?

@BalusC
Member
BalusC commented Jul 1, 2015

Yes it should. As per the stack trace it looks like the NameNotFoundException of interest is being wrapped in a NamingException. What environment is this running in? GlassFish? Which version?

@arjantijms
Member

It looks a bit strange that NameNotFoundException is wrapped in NamingException. Perhaps we could do an unwind of the Exception hierarchy and see if any of the wrapped exceptions is NameNotFoundException, if so, don't throw.

I wonder how common this is though.

@wfsaxton
wfsaxton commented Jul 1, 2015

GlassFish Server Open Source Edition 4.1 (build 13)

Here is the full stack trace:

Warning: StandardWrapperValve[Faces Servlet]: Servlet.service() for servlet Faces Servlet threw exception
java.lang.IllegalStateException: javax.naming.NamingException: Lookup failed for 'devLoginEnabled' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NameNotFoundException: devLoginEnabled not found]
at org.omnifaces.util.JNDI.lookup(JNDI.java:92)
at com.example.escrow.web.SecurityFilter.isDevLoginEnabled(SecurityFilter.java:101)
at com.example.escrow.web.SecurityFilter.getUserEmail(SecurityFilter.java:87)
at com.example.escrow.web.SecurityFilter.getCurrentUser(SecurityFilter.java:83)
at com.example.escrow.web.SecurityFilter.doFilter(SecurityFilter.java:50)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at org.omnifaces.facesviews.FacesViewsForwardingFilter.filterExtensionLess(FacesViewsForwardingFilter.java:128)
at org.omnifaces.facesviews.FacesViewsForwardingFilter.doFilter(FacesViewsForwardingFilter.java:89)
at org.omnifaces.filter.HttpFilter.doFilter(HttpFilter.java:108)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:316)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:415)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:282)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:201)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:175)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:561)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:565)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
at java.lang.Thread.run(Thread.java:745)
Caused by: javax.naming.NamingException: Lookup failed for 'devLoginEnabled' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NameNotFoundException: devLoginEnabled not found]
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:491)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:438)
at javax.naming.InitialContext.lookup(InitialContext.java:417)
at javax.naming.InitialContext.lookup(InitialContext.java:417)
at org.omnifaces.util.JNDI.lookup(JNDI.java:88)
... 38 more
Caused by: javax.naming.NameNotFoundException: devLoginEnabled not found
at com.sun.enterprise.naming.impl.TransientContext.doLookup(TransientContext.java:237)
at com.sun.enterprise.naming.impl.TransientContext.lookup(TransientContext.java:204)
at com.sun.enterprise.naming.impl.SerialContextProviderImpl.lookup(SerialContextProviderImpl.java:66)
at com.sun.enterprise.naming.impl.LocalSerialContextProviderImpl.lookup(LocalSerialContextProviderImpl.java:114)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:478)
... 42 more

@BalusC BalusC added a commit that closed this issue Jul 1, 2015
@BalusC BalusC Fix #141 Some environments unintelligibly wrap NameNotFoundException in
a plain NamingException.
ff948cb
@BalusC BalusC closed this in ff948cb Jul 1, 2015
@BalusC
Member
BalusC commented Jul 1, 2015

Fix is available in today's 2.2-SNAPSHOT. Give it a try and let us know if that does it for you.

@wfsaxton
wfsaxton commented Jul 1, 2015

Thanks for the quick fix. Will test it today.

Stupid question though: what do I put in my Maven pom.xml to access this? (Sorry, I'm fairly new to maven and I just use my IDE to search for the libraries I need and I only see Omnifaces 2.1 available).

Or is 2.2 full release becoming available soon?

@BalusC
Member
BalusC commented Jul 1, 2015

A "snapshot" is just the current/latest build. It's far from a release. To enable snapshots from a certain Maven repo (OSS in our case), add it as <repository> to either ~/.m2/settings.xml (global) or pom.xml (project-specific). See also a.o. http://stackoverflow.com/q/5901378/157882

We may make code changes and create snapshots so now and then before 2.2 release. Those changes will then get reflected in your project if you use the snapshot version in pom. It will generally work just fine, but imagine if we make some mistake and notice it only a few days or weeks later, or are trying to test something which may not necessarily work in all environments, then your project may be affected. That's why it's advisable to not use snapshots of 3rd party libraries in production, unless you have your own build system which can "lock" a specific snapshot version, or closely track (and understand) any changes in the codebase.

@wfsaxton
wfsaxton commented Jul 1, 2015

Thanks for the info. I went ahead and temporarily installed the snapshot to test the fix and I verified it worked.

Will use a workaround until 2.2 gets released.

@BalusC
Member
BalusC commented Jul 1, 2015

Great. Thank you for helping to improve OmniFaces.

@BalusC BalusC added the bug label Oct 3, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment