To reproduce, deploy the attached application on web server and access: /servlet_spec_crosscontext1_web/JSPAccessServlet.jsp?testname=includeJSPServlet or /servlet_spec_crosscontext1_web/JSPAccessServlet.jsp?testname=forwardJSPServlet
Created attachment 11711 [details] web app to reproduce; its source code and class files
How about mentioning the exception as well, in case the problem is obvious ?
The test is bad (it's an EAR): please include a regular test case, as well as the exception report. BTW, given the presence of the default servlet, I do not see how you can expect to get a null RD back (yet another weird test, maybe ?).
I bet this is a duplicate of 23211 http://issues.apache.org/bugzilla/show_bug.cgi?id=23211
Created attachment 11712 [details] Simpler version of the test case - same URL to reproduce
Exception thrown: java.lang.NullPointerException
I can't quite see how your package is simpler. I did waste some time investigating (while my right eye was watching roland garros ;) ), and your bug is really invalid: the NPE is thrown somewhere in your code, and it works (apparently) after setting crossContext in DefaultContext. As a general rule, don't bother filing a bug if: - we can't really know for sure what your test is doing and/or you don't want to tell - you can't post stack traces
Created attachment 11713 [details] third attachment with correct path to a servlet
To respond to Tim Funk's comment -- created a third test case attachment so that a correct servlet path is used when place call ServletContext.getRequestDispatcher(path_servlet). To respond to Remy's comment #1 - with code like this, the exception is from Tomcat: try { rd = context.getRequestDispatcher(path_servlet); } catch (Exception ex) { out.println("Unexpected Exception thrown:" + ex.toString()); } To respond to Remy's comment #2 -- "it works (apparently) after setting crossContext in DefaultContext" -- It should also return null if crossContext not set, not just throwing an exception. Both of them together(!!!) make the picture complete.
Whatever ;) I won't waste any more time of this issue, that's for sure.
If context == null (which it will be by default), then surprise surprise, *your* code will throw an NPE. Please go back and read Remy's comments about how to submit a bug report.
Well, to respond to William Barker's comment - BIG surprise that you didn't read the source code before respond - to quote the more code in the third attachement: ses = req.getSession(true); if (ses != null) { ServletContext context = getServletConfig().getServletContext().getContext(path_context); try { rd = context.getRequestDispatcher(path_servlet); } catch (Exception ex) { out.println("Unexpected Exception thrown:" + ex.toString()); } } else { out.println("Cannot get a HttpSession"); } To respond to Remy's comment since I am back in here - I think this is important to fix - crossContext maynot be always turned on for security reason.
If crossContext is false then "getContext(path_context)" would return null. If context is null then trying to call one of it's methods will always yield a NullPointerException. rd = context.getRequestDispatcher(path_servlet); IOW: There is no context to respond to the "getRequestDispatcher" call.
Response to Ben Souther and william.barker, thanks, ServletContext returned Null in this case. Test error.