aspose file tools*
The moose likes JSP and the fly likes Baffling NPE in <c:forEach Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Baffling NPE in <c:forEach" Watch "Baffling NPE in <c:forEach" New topic
Author

Baffling NPE in <c:forEach

Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4659
    
    5

I'm getting a NPE exception, only for the ${applicationScope} loop.
The rest work fine.




It seems to be the ${entry.value} is blowing up. Changing it to
${entry} still causes the NPE.

I dont' see how ${entry} can be null in the forEach iteration.
What am I doing wrong?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61616
    
  67

Working fine for me. What have you placed into app scope?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4659
    
    5

Bear Bibeault wrote:Working fine for me. What have you placed into app scope?


If I knew, I could fix it, right?

Here is what I get from EL on that part.


Application Scope: com.sun.appserv.tld.map
com.sun.jsp.tldUriToLocationMap
com.sun.jsp.tagFileJarUrlsCache
jspx.1st.request
repdrawingbase
javax.servlet.context.tempdir
com.sun.appserv.jsp.resource.injector
com.sun.jsp.taglibraryCache
org.apache.catalina.resources
org.glassfish.jsp.isStandaloneWebapp
ptoquery
org.apache.catalina.jsp_classpath
McpParameters
org.glassfish.servlet.habitat
org.glassfish.jsp.monitor.probeEmitter
javax.servlet.context.orderedLibs
timezonelist
com.sun.appserv.tldlistener.map
staticurl
com.sun.faces.useMyFaces

Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1018
Does it give you a stack trace for the null pointer exception pointing out the rogue class?

My bet would be on one of the custom application attributes you have put into scope (ie those without a package/qualified namespace)
- repdrawingbase
- ptoquery
- McpParameters
- timezonelist
- staticurl

Could the toString() method of any of these objects produce a null pointer exception?

Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4659
    
    5

That's my guess as well. The stackdump is not useful. And Netbeans doesn't want to set breakpoints in the generated java code for the JSP.

I don't understand how the ${entry} can be null and the problem, when it lists out the ${entry.key}

I'll look at the toString() and if that fails, start removing items from the context
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61616
    
  67

entry is not likely null at any time. But the default action is to emit the string equivalents of the key and value. So as Stephan pointed out, the toString()'s of any of the entry keys or values can cause this issue if they NPPE.
Cyrille Le Clerc
Greenhorn

Joined: Jul 19, 2009
Posts: 6
I faced the same NPE with Jetty 7.6, it is caused by calling toString() on servletContext.getAttribute("com.sun.jsp.taglibraryCache") which returns a java.util.concurrent.ConcurrentHashMap.

The stack trace is :


Hope this helps,

Cyrille


Cyrille Le Clerc
cleclerc@xebia.fr, http://blog.xebia.fr/
 
 
subject: Baffling NPE in <c:forEach