Bug 29327 - ServletContext.getRequestDispatcher(path_servlet) throws Exception instead of returning null
Summary: ServletContext.getRequestDispatcher(path_servlet) throws Exception instead of...
Status: RESOLVED INVALID
Alias: None
Product: Tomcat 5
Classification: Unclassified
Component: Servlet & JSP API (show other bugs)
Version: 5.0.25
Hardware: Sun Solaris
: P3 major (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-06-01 17:53 UTC by Dianne Jiao
Modified: 2004-11-16 19:05 UTC (History)
0 users



Attachments
web app to reproduce; its source code and class files (30.40 KB, application/octet-stream)
2004-06-01 17:55 UTC, Dianne Jiao
Details
Simpler version of the test case - same URL to reproduce (23.05 KB, application/octet-stream)
2004-06-01 18:38 UTC, Dianne Jiao
Details
third attachment with correct path to a servlet (16.37 KB, application/octet-stream)
2004-06-01 19:08 UTC, Dianne Jiao
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Dianne Jiao 2004-06-01 17:53:15 UTC
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
Comment 1 Dianne Jiao 2004-06-01 17:55:33 UTC
Created attachment 11711 [details]
web app to reproduce; its source code and class files
Comment 2 Remy Maucherat 2004-06-01 17:56:08 UTC
How about mentioning the exception as well, in case the problem is obvious ?
Comment 3 Remy Maucherat 2004-06-01 17:59:16 UTC
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 ?).
Comment 4 Tim Funk 2004-06-01 18:20:28 UTC
I bet this is a duplicate of 23211

http://issues.apache.org/bugzilla/show_bug.cgi?id=23211
Comment 5 Dianne Jiao 2004-06-01 18:38:27 UTC
Created attachment 11712 [details]
Simpler version of the test case - same URL to reproduce
Comment 6 Dianne Jiao 2004-06-01 18:39:16 UTC
Exception thrown:
java.lang.NullPointerException

Comment 7 Remy Maucherat 2004-06-01 18:51:40 UTC
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
Comment 8 Dianne Jiao 2004-06-01 19:08:41 UTC
Created attachment 11713 [details]
third attachment with correct path to a servlet
Comment 9 Dianne Jiao 2004-06-01 19:14:32 UTC
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.
Comment 10 Remy Maucherat 2004-06-01 19:22:46 UTC
Whatever ;) I won't waste any more time of this issue, that's for sure.
Comment 11 william.barker 2004-06-01 20:01:43 UTC
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.
Comment 12 Dianne Jiao 2004-06-01 20:10:49 UTC
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.
Comment 13 Ben Souther 2004-06-01 20:18:26 UTC
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.
Comment 14 Dianne Jiao 2004-06-01 21:03:25 UTC
Response to Ben Souther and william.barker, thanks, ServletContext returned Null
in this case.  

Test error.