Hi,

2017-03-23 22:47 GMT+02:00 Thomas DELHOMENIE <thomas.delhome...@gmail.com>:
>
> Hi,
>
> With Tomcat 8.5.12 I hit a NPE when I use RequestDispatcher to redirect
> from a servlet to another one in the case of the mapping of this second
> servlet ends with /*. An error 500 is returned because of a
> NullPointerException :

Most probably you are facing this issue [1].
The fix will be available in 8.5.13.

Regards,
Violeta

[1] https://bz.apache.org/bugzilla/show_bug.cgi?id=60882

>  java.lang.NullPointerException
>         at
>
org.apache.catalina.core.ApplicationMapping.getServletMapping(ApplicationMapping.java:62)
>         at
>
org.apache.catalina.core.ApplicationContext.getRequestDispatcher(ApplicationContext.java:486)
>         at
>
org.apache.catalina.core.ApplicationContextFacade.getRequestDispatcher(ApplicationContextFacade.java:222)
>         at org.exoplatform.RedirectServlet.doGet(RedirectServlet.java:19)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:635)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
>         at
>
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
>         at
>
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
>         at
> org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
>         at
>
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
>         at
>
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
>         at
>
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
>         at
>
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
>         at
>
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
>         at
>
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80)
>         at
>
org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624)
>         at
>
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
>         at
>
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:341)
>         at
> org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:783)
>         at
>
org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
>         at
>
org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:798)
>         at
>
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1441)
>         at
>
org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
>         at
>
java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1161)
>         at
>
java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
>         at
>
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
>         at java.base/java.lang.Thread.run(Thread.java:844)
>
> To reproduce this issue I created a simple war with the following web.xml
:
>
> <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee";
>   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
>   xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
>                       http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd";
>   version="3.1"
>   metadata-complete="true">
>
>     <description>
>       Servlet and JSP Examples.
>     </description>
>     <display-name>Servlet and JSP Examples</display-name>
>
>     <servlet>
>       <servlet-name>HelloWorldExample</servlet-name>
>       <servlet-class>org.sample.HelloWorldServlet</servlet-class>
>     </servlet>
>     <servlet>
>         <servlet-name>RedirectServlet</servlet-name>
>         <servlet-class>org.sample.RedirectServlet</servlet-class>
>     </servlet>
>
>     <servlet-mapping>
>         <servlet-name>HelloWorldExample</servlet-name>
>         <url-pattern>/HelloWorldExample/*</url-pattern>
>     </servlet-mapping>
>     <servlet-mapping>
>         <servlet-name>RedirectServlet</servlet-name>
>         <url-pattern>/RedirectServlet</url-pattern>
>     </servlet-mapping>
> </web-app>
>
> The class RedirectServlet is :
>
> package org.sample;
>
> import javax.servlet.RequestDispatcher;
> import javax.servlet.ServletException;
> import javax.servlet.http.HttpServlet;
> import javax.servlet.http.HttpServletRequest;
> import javax.servlet.http.HttpServletResponse;
> import java.io.IOException;
>
> public class RedirectServlet extends HttpServlet {
>   @Override
>   public void doGet(HttpServletRequest request,
>                     HttpServletResponse response)
>           throws IOException, ServletException
>   {
>     RequestDispatcher requestDispatcher =
> request.getServletContext().getRequestDispatcher("/HelloWorldExample");
>     requestDispatcher.forward(request, response);
>   }
> }
>
> And the class HelloWorldServlet is :
>
> package org.sample;
>
> import javax.servlet.ServletException;
> import javax.servlet.http.HttpServlet;
> import javax.servlet.http.HttpServletRequest;
> import javax.servlet.http.HttpServletResponse;
> import java.io.IOException;
> import java.io.PrintWriter;
>
> public class HelloWorldServlet extends HttpServlet {
>   @Override
>   public void doGet(HttpServletRequest request,
>                     HttpServletResponse response)
>           throws IOException, ServletException
>   {
>     PrintWriter out = response.getWriter();
>
>     out.println("<!DOCTYPE html><html>");
>     out.println("<head>");
>     out.println("<meta charset=\"UTF-8\" />");
>     out.println("<title>Hello World</title>");
>     out.println("</head>");
>     out.println("<body bgcolor=\"white\">");
>     out.println("<a href=\"../helloworld.html\">");
>     out.println("<img src=\"../images/code.gif\" height=24 " +
>             "width=24 align=right border=0 alt=\"view code\"></a>");
>     out.println("<a href=\"../index.html\">");
>     out.println("<img src=\"../images/return.gif\" height=24 " +
>             "width=24 align=right border=0 alt=\"return\"></a>");
>     out.println("<h1>Hello World !</h1>");
>     out.println("</body>");
>     out.println("</html>");
>   }
> }
>
> I do not have this issue with Tomcat 8.5.11.
> I also do not have this issue if I change the mapping of the servlet
> HelloWorldExample to "/HelloWorldExample" instead of
"/HelloWorldExample/*".
>
> It looks like a bug but I wanted to be sure of that before opening an
issue
> in the bugtracker. Should I open one ?
>
> Thanks

Reply via email to