Uploaded image for project: 'ShrinkWrap'
  1. ShrinkWrap
  2. SHRINKWRAP-306

URL.openStream on directory URLs from the ShrinkWrapClassLoader throw an NPE

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Major
    • 1.0.0-beta-5
    • 1.0.0-beta-4
    • api
    • None

    Description

      This case should show the problem:

            // Make a new Archive with some content in a directory
            final String nestedResourceName = "nested/test";
            final Asset testAsset = new StringAsset("testContent");
            final GenericArchive archive = ShrinkWrap.create(GenericArchive.class).add(testAsset, nestedResourceName);
            
            // Make a CL to load the content
            final ClassLoader swCl = new ShrinkWrapClassLoader(archive);
      
            // Get the URL to the parent directory
            final URL nestedResourceUrl = swCl.getResource(nestedResourceName);
            final URL nestedResourceUpALevelUrl = new URL(nestedResourceUrl, "../");
            
            // openStream on the URL to the parent directory; should return null, not throw an exception
            final InputStream in = nestedResourceUpALevelUrl.openStream(); // << NPE

      Due to:

      https://github.com/shrinkwrap/shrinkwrap/blob/1.0.0-beta-4/api/src/main/java/org/jboss/shrinkwrap/api/classloader/ShrinkWrapClassLoader.java#L134

      If "getAsset" from Node is returning null, this is a directory. So return a null InputStream to denote as such; don't throw an NPE.

      Attachments

        Issue Links

          Activity

            People

              arubinge@redhat.com Andrew Rubinger (Inactive)
              arubinge@redhat.com Andrew Rubinger (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: