Uploaded image for project: 'JBoss Modules'
  1. JBoss Modules
  2. MODULES-115

JarFileResourceLoader.getResource implementation is broken in Windows, as it returns a Resource (JarEntryResource) with invalid URL

    XMLWordPrintable

Details

    • Workaround Exists
    • Hide

      Workaround (to decode) is very ugly, and it may not be possible to fix in most of the dependent libraries.

      Show
      Workaround (to decode) is very ugly, and it may not be possible to fix in most of the dependent libraries.

    Description

      Current implementation of JarFileResourceLoader.getResource depends on the Operating System in which the server is installed. As a result, for a JAR file, it returns a Resource (JarEntryResource) with invalid URL.

      Current code:

      return new JarEntryResource(jarFile, entry, new URI("jar", "file:" + jarFile.getName() + "!/" + entry.getName(), null).toURL());
      

      This is buggy, because jarFile.getName() call is platform dependent, and the URI constructor encodes the file-path, making the URI invalid in Windows.

      For eg. Say the JAR is located in c:/x.jar, then new URI() call above will parse the arguments into "jar:file:c:%5Cx.jar!/org/..." URI format, which is invalid. However, the expected URI needs to be "jar:file:/c:/x.jar!/org/..." irrespective of in which platform the application server is running.

      Fix:

      1. Instead of jarFile.getName(), you need something like new File(jarFile.getName()).toURI().toString(). Please find the attached patch file.
      2. This may NOT be an isolated case, and hence, if you are using similar logic somewhere else, then those places need similar fixes.

      Attachments

        Activity

          People

            dlloyd@redhat.com David Lloyd
            abhis_jira Abhi S (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: