It is clear that there is another exception.
Maybe "messages", inside the catch is null and it is throwing a new NullPointerException?
Question
I'm breaking my head with this:
protected void setParameters(HttpServletRequest request) {
try {
page = Integer.parseInt(request.getParameter("p"));
}
catch (NumberFormatException | NullPointerException e) {
messages.add("Invalid page.");
}
try {
status = Integer.parseInt(request.getParameter("s"));
}
catch (NumberFormatException | NullPointerException e) {
messages.add("Invalid status.");
}
}
Before I placed this method into a super class it was working as expected; but now when I have a query string without the p parameter (for example), the exception (NumberFormatException) is thrown (as expected), then caught by the first catch (as expected) and then rethrown and caught by the calling function (this is not expected). Since the exception was already caught here, the execution should just continue.
I'm attaching a screenshot where you can see:
Any ideas are very appreciated
Update:
Thank you, this is my calling stack: Servlet > UserListHandler > setParameters
UserListHandler() is a contructor and looks like this:
Servlet looks like this:
I find interesting that the exception the servlet is catching is a NullPointerException.
The top of my stack trace looks like this:
Mar 31, 2014 5:13:06 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [UserListServlet] in context with path [/App.Web] threw exception [java.lang.NullPointerException] with root cause
java.lang.NullPointerException
Solution
It is clear that there is another exception.
Maybe "messages", inside the catch is null and it is throwing a new NullPointerException?