Velocity
  1. Velocity
  2. VELOCITY-590

JarResourceLoader does not accept paths inside JAR files

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.5
    • Fix Version/s: 1.6
    • Component/s: Engine
    • Labels:
      None

      Description

      According to documentation of JarResourceLoader it accepts paths that conform to rules given by java.net.JarUrlConnection. This is however not true as the JarUrlConnection says that the URL has form

      jar:<url>!/

      {entry}

      The "!/" is mandatory part of the URL. JarResourceLoader however expects the path whitout this suffix and automatically appends it. When conforming URL is given JarResourceLoader makes it invalid

      eg.

      /directory/file.jar!/META-INF/templates/

      is scrambled to

      /directory/file.jar!/META-INF/templates/!/

      which is invalid and no templates are found.

      I try to package templates along with tools and other code. I put them into /META-INF/templates/ and try to setup the loader so I do not have to prefix template names with "/META-INF/templates/".

      ======

      Ideally the JarResourceLoader should not append "!/" suffix at all. For compatibility reasons it should do so only if the path does not contain it already.

        Activity

        Ales Dolecek created issue -
        Ales Dolecek made changes -
        Field Original Value New Value
        Description According to documentation of JarResourceLoader it accepts paths that conform to rules given by java.net.JarUrlConnection. This is however not true as the JarUrlConnection says that the URL has form

        jar:<url>!/{entry}

        The "!/" is mandatory part of the URL. JarResourceLoader however expects the path whitout this suffix and automatically appends it. When conforming URL is given JarResourceLoader makes it invalid

        eg.

        /directory/file.jar!/META-INF/templates/

        is scrambled to

        /directory/file.jar!/META-INF/templates/!/

        which is invalid and no templates are found.

        I try to package templates along with tools and other code. I put them into /META-INF/templates/ and try to setup the loader so I do not have to prefix template names with "/META-INF/templates/".

        ======

        Ideally the JarResourceLoader should not append "!/" suffix at all. For compatibility reasons it should do so only if the path does not contain it already.
        According to documentation of JarResourceLoader it accepts paths that conform to rules given by java.net.JarUrlConnection. This is however not true as the JarUrlConnection says that the URL has form

        jar:<url>!/{entry}

        The "!/" is mandatory part of the URL. JarResourceLoader however expects the path whitout this suffix and automatically appends it. When conforming URL is given JarResourceLoader makes it invalid

        eg.

        /directory/file.jar!/META-INF/templates/

        is scrambled to

        /directory/file.jar!/META-INF/templates/!/

        which is invalid and no templates are found.

        I try to package templates along with tools and other code. I put them into /META-INF/templates/ and try to setup the loader so I do not have to prefix template names with "/META-INF/templates/".

        ======

        Ideally the JarResourceLoader should not append "!/" suffix at all. For compatibility reasons it should do so only if the path does not contain it already.

        Simply change

                if ( !path.endsWith("!/") )
                {
                    path += "!/";
                }

        to

                if ( !path.contains("!/") )
                {
                    path += "!/";
                }
        Ales Dolecek made changes -
        Description According to documentation of JarResourceLoader it accepts paths that conform to rules given by java.net.JarUrlConnection. This is however not true as the JarUrlConnection says that the URL has form

        jar:<url>!/{entry}

        The "!/" is mandatory part of the URL. JarResourceLoader however expects the path whitout this suffix and automatically appends it. When conforming URL is given JarResourceLoader makes it invalid

        eg.

        /directory/file.jar!/META-INF/templates/

        is scrambled to

        /directory/file.jar!/META-INF/templates/!/

        which is invalid and no templates are found.

        I try to package templates along with tools and other code. I put them into /META-INF/templates/ and try to setup the loader so I do not have to prefix template names with "/META-INF/templates/".

        ======

        Ideally the JarResourceLoader should not append "!/" suffix at all. For compatibility reasons it should do so only if the path does not contain it already.

        Simply change

                if ( !path.endsWith("!/") )
                {
                    path += "!/";
                }

        to

                if ( !path.contains("!/") )
                {
                    path += "!/";
                }
        According to documentation of JarResourceLoader it accepts paths that conform to rules given by java.net.JarUrlConnection. This is however not true as the JarUrlConnection says that the URL has form

        jar:<url>!/{entry}

        The "!/" is mandatory part of the URL. JarResourceLoader however expects the path whitout this suffix and automatically appends it. When conforming URL is given JarResourceLoader makes it invalid

        eg.

        /directory/file.jar!/META-INF/templates/

        is scrambled to

        /directory/file.jar!/META-INF/templates/!/

        which is invalid and no templates are found.

        I try to package templates along with tools and other code. I put them into /META-INF/templates/ and try to setup the loader so I do not have to prefix template names with "/META-INF/templates/".

        ======

        Ideally the JarResourceLoader should not append "!/" suffix at all. For compatibility reasons it should do so only if the path does not contain it already.
        Ales Dolecek made changes -
        Attachment JarResourceLoaderFix.java [ 12377796 ]
        Ales Dolecek made changes -
        Comment [ Here is my rewrite of your JarResourceLoader - maybe it helps.

        I'm sorry for use of Java 1.5 constructs but I had to adhere to company policy.

        ]
        Ales Dolecek made changes -
        Attachment JarResourceLoaderFix.java [ 12377796 ]
        Hide
        Ales Dolecek added a comment -

        Here is my rewrite of your JarResourceLoader - maybe it helps.

        I'm sorry for use of Java 1.5 constructs but I had to adhere to company policy.

        Show
        Ales Dolecek added a comment - Here is my rewrite of your JarResourceLoader - maybe it helps. I'm sorry for use of Java 1.5 constructs but I had to adhere to company policy.
        Ales Dolecek made changes -
        Attachment JarResourceLoaderFix.java [ 12377814 ]
        Hide
        Nathan Bubna added a comment -

        ok, it will now only append !/ when the path does not contain it already.

        Show
        Nathan Bubna added a comment - ok, it will now only append !/ when the path does not contain it already.
        Nathan Bubna made changes -
        Fix Version/s 1.6 [ 12310290 ]
        Resolution Fixed [ 1 ]
        Status Open [ 1 ] Resolved [ 5 ]
        Mark Thomas made changes -
        Workflow jira [ 12425978 ] Default workflow, editable Closed status [ 12551560 ]
        Mark Thomas made changes -
        Workflow Default workflow, editable Closed status [ 12551560 ] jira [ 12552445 ]

          People

          • Assignee:
            Unassigned
            Reporter:
            Ales Dolecek
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development