ProtectionDomain.getCodeSource().getLocation() returns VFS URL with trailing slash,
subsequently interpreted as path when creating new URL
------------------------------------------------------------------------------------------------------------------------------------------
Key: JBVFS-171
URL:
https://issues.jboss.org/browse/JBVFS-171
Project: JBoss VFS
Issue Type: Bug
Security Level: Public (Everyone can see)
Components: Release
Affects Versions: 3.0.0.CR5
Environment: Platform doesn't really matter; problem seen with JBoss 6.0.0
Final on Red Hat Enterprise Linux 4 (64-bit) and Windows XP (32-bit).
Reporter: Jon Schuster
Assignee: John Bailey
Webapp has a non-jar auxiliary file located in WEB-INF/lib, alongside main application
jar. To load contents of aux file, webapp calls
<currentClass>.getProtectionDomain().getCodeSource().getLocation() to get URL of
main application jar. JBoss returns a VFS URL to the application jar inside the webapp
.war or .ear file, but VFS URL has a slash at the end. Subsequent call to new URL( jarurl,
auxfilename ) results in a new VFS URL with the aux filename appended after the trailing
slash, rather than locating the aux file relative to the application jar.
For example, CodeSource.getLocation() returns this URL:
{{{
vfs:/C:/Development/jboss/jboss-6.0.0.Final/server/default/deploy/testservlet.war/WEB-INF/lib/TestServlet.jar/
}}}
Creating a new URL using "new URL( aboveurl, "testfile.txt" )" results
in this URL:
{{{
vfs:/C:/Development/jboss/jboss-6.0.0.Final/server/default/deploy/testservlet.war/WEB-INF/lib/TestServlet.jar/testfile.txt
}}}
A subsequent attempt to read from the testfile.txt using
URL.openConnection().getInputStream() fails with a FileNotFoundException.
Because of the trailing slash on the VFS URL to the application jar, the context used by
the URL class to construct the new relative URL to the auxiliary file is incorrect, making
the auxiliary file inaccessible.
--
This message is automatically generated by JIRA.
For more information on JIRA, see:
http://www.atlassian.com/software/jira