Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Minor
-
Resolution: Fixed
-
Affects Version/s: None
-
Fix Version/s: 6.1.25
-
Component/s: None
-
Labels:None
-
Number of attachments :
Description
Code to reproduce:
ServletHolder servletHolder = new ServletHolder(new BotServlet());
root.addServlet( servletHolder, "/bot/*" );
ServletHolder defaultSH = new ServletHolder(new org.mortbay.jetty.servlet.DefaultServlet());
defaultSH.setInitParameter("relativeResourceBase", "./src/main/java/org/myapp/web/files");
root.addServlet(defaultSH, "/");
DefaultServlet.java @ 181 (in Jetty 6.1.24):
_resourceBase = _context.getContextHandler().getResource(URIUtil.SLASH).addPath(rrb);
// getResource() returns null, so Jetty logs:
03:46:17.751 INFO [main] / Unavailable javax.servlet.UnavailableException: java.lang.NullPointerException
I suggest to handle this case and throw an exceptio with an explaination of what's the cause.
Confirmed this issue with current trunk of Jetty 6. It is caused by the code that embeds Jetty failing to set the the resourceBase of Context that the servlet is being added to, that is an error in configuration of the context and not DefaultServlet. This issue does not apply Jetty 7.
Below is the proper way of configuring a context in order to use the relativeResourceBase init parameter for the DefaultServlet.
Context context = new Context(server,"/test",Context.SESSIONS);
context.setResourceBase(new File("./src/test").getAbsolutePath());
server.setHandler(context);
ServletHolder defaultSH = new ServletHolder(new DefaultServlet());
defaultSH.setInitParameter("relativeResourceBase", "./resources");
context.addServlet(defaultSH, "/");
The way to fix this issue is to deconstruct that statement to first check the result of ContextHandler.getResource() method call and if it is equal to null put an explicit error message into the log. This should take about 1h to fix.