[jboss-jira] [JBoss JIRA] Commented: (JBCL-177) ProtectionDomain.getCodeSource().getLocation() returns VFS URL with trailing slash, subsequently interpreted as path when creating new URL
David Lloyd (JIRA)
jira-events at lists.jboss.org
Thu Mar 10 12:52:46 EST 2011
[ https://issues.jboss.org/browse/JBCL-177?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12587235#comment-12587235 ]
David Lloyd commented on JBCL-177:
----------------------------------
The class loader could be using the non-trailing-slash variant for code sources.
> ProtectionDomain.getCodeSource().getLocation() returns VFS URL with trailing slash, subsequently interpreted as path when creating new URL
> ------------------------------------------------------------------------------------------------------------------------------------------
>
> Key: JBCL-177
> URL: https://issues.jboss.org/browse/JBCL-177
> Project: JBoss ClassLoader
> Issue Type: Bug
> Components: VFS
> 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
> Labels: codesource, getlocation, vfs
>
> 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
More information about the jboss-jira
mailing list