Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Details on NullPointerException in JSP?

I am getting a null pointer exception in jsp and I want to find out what line has the null variable so i can fix it. Is there any simple way to do this? The printStackTrace didn't seem to give me any relevant information.

Stack Trace:

java.lang.NullPointerException 
    at org.apache.jsp.data.index2_jsp._jspService(index2_jsp.java:176) 
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:802) 
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331) 
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329) 
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:802) 
    at sun.reflect.GeneratedMethodAccessor103.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Method.java:616) 
    at org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:244) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at javax.security.auth.Subject.doAsPrivileged(Subject.java:537) 
    at org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:276) 
    at org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:162) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:262) 
    at org.apache.catalina.core.ApplicationFilterChain.access$0(ApplicationFilterChain.java:192) 
    at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:171) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:167) 
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213) 
    at org.apache.catalina.co
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:525) 
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) 
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117) 
    at org.apache.catalina.authenticator.SingleSignOn.invoke(SingleSignOn.java:420)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
    at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665) 
    at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528) 
    at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81) 
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689) 
    at java.lang.Thread.run(Thread.java:636) 
like image 796
Lye Avatar asked Apr 16 '10 23:04

Lye


People also ask

How do I check NullPointerException?

NullPointerException is thrown when a reference variable is accessed (or de-referenced) and is not pointing to any object. This error can be resolved by using a try-catch block or an if-else condition to check if a reference variable is null before dereferencing it.

Can you catch a NullPointerException?

Programmers typically catch NullPointerException under three circumstances: The program contains a null pointer dereference. Catching the resulting exception was easier than fixing the underlying problem. The program explicitly throws a NullPointerException to signal an error condition.

What is NullPointerException in JSP?

A NullPointerException occurs during translation of a JSP file which contains a custom tag. During the translation phase of a JSP file a NullPointerException can occur. The exception is caused if a custom tag has an attribute where the expected return type is an array.


1 Answers

It's not pretty but you could go into the work directory and find the specified Java file (the converted JSP) and see what operations are on the specified line. Generally Tomcat will keep the source for the generated servlet around unless configured not to. It should at least help you find the error-point or the corresponding JSP line.

Hope this helps.

like image 113
cjstehno Avatar answered Oct 25 '22 01:10

cjstehno