google / google/guice

RequestDispatcher forward fail if served page is the the welcome file

Open
#560 4 comments 0 reactions 0 assignees View on GitHub
Extension-Servlet imported
Dominant language
Java
Stars
12.7k
Forks
1.7k
Avg merge
11m
Merged PRs (30d)
2

Description

_From [nicolas.antoniazzi](https://code.google.com/u/101980382079451363147/) on October 21, 2010 04:57:47_

If I want that my welcome file be a servlet that forward its rendering to a jsp page, the process crashes in com.google.inject.servlet.ServletDefinition$2.getPathInfo(ServletDefinition.java:206)

with :

java.lang.StringIndexOutOfBoundsException: String index out of range: -9
        at java.lang.String.substring(String.java:1937)
        at java.lang.String.substring(String.java:1904)
        at com.google.inject.servlet.ServletDefinition$2.getPathInfo(ServletDefinition.java:206)
        at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:359)
        at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
        at com.cartser.metrics.server.core.servlet.GwtServlet.doLoad(GwtServlet.java:89)
        at com.cartser.metrics.server.core.servlet.GwtServlet.doGet(GwtServlet.java:94)

...

The problem is coming from a substring operation in getPathInfo()

  final int servletPathLength = getServletPath().length();
  pathInfo = getRequestURI().substring(getContextPath().length()).replaceAll("[/]{2,}", "/").substring(servletPathLength);

  in my case :
getServletPath() = /index.jsp
getContextPath() = /myApp
getRequestURI() = /myApp (and not /myApp/index.jsp since index.jsp is declared as the default welcome file)
servletPathLength = 10

so when executing the substring operation with my URI :
getRequestURI().substring(getContextPath().length()).replaceAll("[/]{2,}", "/") ==> "/"
and "/".substring(10) ==> Exception.

Maybe that a check could be added on the length before executing the second substring() operation.

_Original issue: http://code.google.com/p/google-guice/issues/detail?id=560_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.