views:

726

answers:

3

I'm currently using Apache Tomcat 5.5.16 to serve a Lucene-based search API.

Lately I've been having some NullPointerExceptions inside my servlet class. The class is called com.my_company.search.servlet.SearchServlet.

With certain types of input I can routinely create a NullPointerException, but I'm having trouble figuring out where exactly it is.

The StackTrace indicates that the bug is occuring here: com.my_company.search.servlet.SearchServlet.doGet(Unknown Source)

The source and .class files for this class is all in: $TOMCAT_HOME/webapps/my_servlet/WEB-INF/classes/com/my_company/search/servlet/

My question is, how can I get Tomcat to provide me with more descriptive error locations?

+6  A: 

Tomcat cannot provide you more detailed information unless the classes in question were compiled with debugging information. Without this debugging information, the JVM cannot determine what line of code the error occurred on.

Edit: You can ask the compiler to include this information by specifying the -g option when running javac on the command line. You can also specify this option using the debug parameter of the Javac Ant task.

Adam Paynter
+1, and if using Eclipse to compile similar was discussed yesterday http://stackoverflow.com/questions/939194/preserving-parameter-argument-names-in-compiled-java-classes
Pool
+1, with the added comment that you likely need to think about refactoring your doGet method - if your methods are small enough and do sufficiently little, just knowing what input was null and what method it was in would probably be sufficient. (but compiling with debugging turned on is definitely the answer to your immediate problem.)
Jared
Thanks this was hugely helpful. I added debug=true to the javac section of the build file and it worked perfectly.And yes. There's no question I need to refactor my doGet =)
zorlack
A: 

the location unknown source can occurs when the JIT compiler has optimized your class. At that point the source information is lost. to get the original location, restart the server and retry your test. Most of the time you will get the location in your source

Salandur
A: 

you have to add debugging information to your classes. compile them with the option -g:

javac -g YourServlet.java
cd1