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

Adding Resources via Classloader found in packaged jars results in NullPointerException

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Critical Critical
    • 1.0.0-beta-2
    • 1.0.0-alpha-13, 1.0.0-beta-1
    • impl-base
    • None

      Adding a Resource via the String representation pointing to a Resource loaded via a ClassLoader and stored in Jar results in NullPoiinterException.

      StackTrace
      java.lang.NullPointerException
      	at org.jboss.shrinkwrap.impl.base.container.ContainerBase.addAsManifestResource(ContainerBase.java:608)
      	at org.jboss.shrinkwrap.impl.base.container.ContainerBase.addAsManifestResource(ContainerBase.java:557)
      	at org.jboss.shrinkwrap.impl.base.container.ContainerBase.addAsManifestResource(ContainerBase.java:545)
      	at org.jboss.shrinkwrap.impl.base.test.DynamicContainerTestBase.testAddManifestStringTargetResourceFromJar(DynamicContainerTestBase.java:303)
      
      org.jboss.shrinkwrap.impl.base.test.DynamicContainerTestBase
         @Test
         @ArchiveType(ManifestContainer.class)
         public void testAddManifestStringTargetResourceFromJar() throws Exception {
            getManifestContainer().addAsManifestResource("java/lang/String.class", "String.class");
            
            ArchivePath testPath = new BasicPath(getManifestPath(), "String.class");
            Assert.assertTrue(
                  "Archive should contain " + testPath,
                  getArchive().contains(testPath));
         }
      

      The faulty logic comes from ContainerBase.fileFromResource(String), a URL returned by CL.getResource when packaged in a Jar is not usable as a new File(url.getFile()), the returned value is in the format: file:/usr/lib/jvm/java-6-openjdk/jre/lib/rt.jar!/java/lang/String.class

      The File has the following states:

      • !file.isFile,
      • !file.isDirectory
      • !file.exists,
      • file.listFiles == null
      • new FileInputStream(file) throws FileNotFoundException

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

                Created:
                Updated:
                Resolved: