users@jersey.java.net

StringIndexOutOfBoundsException

From: Berg,Jon <Jon.Berg_at_Cerner.com>
Date: Thu, 20 Aug 2009 10:28:00 -0500

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.