users@jersey.java.net

Re: [Jersey] StringIndexOutOfBoundsException

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Thu, 20 Aug 2009 18:15:39 +0200

Hi Jon,

What Web container are you using? and what servlet pattern are you
using?

Can you try testing with the following Jersey 1.1.1-ea sample:

   http://download.java.net/maven/2/com/sun/jersey/samples/helloworld-webapp/1.1.1-ea/helloworld-webapp-1.1.1-ea-project.zip

With the URL:

   http://localhost:8080/helloworld-webapp

Paul.

On Aug 20, 2009, at 5:28 PM, Berg,Jon wrote:

> I have encountered an issue using jersey 1.0.3 with context paths
> that appears to have been addressed twice before [1,2] but may have
> regressed.
>
> In the following scenario, I have created a sample jersey web app
> and deployed it to my localhost at the context path “/context”.
> When I attempt to view this web app in any browser using the URL “http://localhost:8080/context
> ”, I receive the following message:
>
> Error 500: java.lang.StringIndexOutOfBoundsException: String index
> out of range: 9
>
> However, when I use the URL “http://localhost:8080/context/”, the
> browser correctly brings up the web app.
>
> The issue appears to be in
> com.sun.jersey.spi.container.ContainerRequest#getEncodedPath(). In
> lines 315-316, the code attempts to retrieve the substring of the
> raw path of the request URI, which in this case is “/context”, after
> the length of the base URI raw path, which is “/context/”. Since “/
> context/” is longer than “/context”, the substring() call fails with
> a StringIndexOutOfBoundsException.
>
> Like I said previously, this issue has been addressed twice before,
> so if it is fixed in a later release, I would appreciate it if you
> could direct me to that. Thank you.
>
> [1] https://jersey.dev.java.net/issues/show_bug.cgi?id=19
>
> [2] https://jersey.dev.java.net/issues/show_bug.cgi?id=75
>
>
> Jon Berg
>
>
> CONFIDENTIALITY NOTICE This message and any included attachments are
> from Cerner Corporation and are intended only for the addressee. The
> information contained in this message is confidential and may
> constitute inside or non-public information under international,
> federal, or state securities laws. Unauthorized forwarding,
> printing, copying, distribution, or use of such information is
> strictly prohibited and may be unlawful. If you are not the
> addressee, please promptly delete this message and notify the sender
> of the delivery error by e-mail or you may call Cerner's corporate
> offices in Kansas City, Missouri, U.S.A at (+1) (816)221-1024.