Uploaded image for project: 'Weld'
  1. Weld
  2. WELD-958

URLScanner parses the wrong META-INF/beans.xml files if the parent classloader has a META-INF/beans.xml file

    Details

    • Type: Bug
    • Status: Resolved (View Workflow)
    • Priority: Critical
    • Resolution: Done
    • Affects Version/s: 1.1.2.Final
    • Fix Version/s: 1.1.3.Final
    • Component/s: None
    • Labels:
      None

      Description

      Note that WELD-714 (fixed for 1.1.0.CR1) does NOT fix this in weld 1.1.2.Final.

      Here's the code that causes the problem:

      public class URLScanner
      {
      ...
         protected void handleArchiveByFile(File file, ...) ...
         {
            ...
      
               ZipFile zip = new ZipFile(file);
               Enumeration<? extends ZipEntry> entries = zip.entries();
               // Replace out the default classloader with one for the zip
               URLClassLoader classLoader = new URLClassLoader(new URL[] { file.toURI().toURL() }); // PROBLEM PART 1: delegates first to parent classloader
               while (entries.hasMoreElements())
               {
                  ZipEntry entry = entries.nextElement();
                  String name = entry.getName();
                  handle(..., classLoader.getResource(name), ...); // PROBLEM PART 2: if parent classloader contains that name, the file content is ignored!
               }
            ...
         }
      ...
      }
      

      Here's what's happens with this input:

      file = /tmp/tomcat-embedded-6/work/arquillian-tomcat-embedded-6/localhost/guvnor-webapp-5.3.0-SNAPSHOT/WEB-INF/lib/seam-persistence-api-3.1.0.Beta2.jar
      classLoader = URL is file:/tmp/tomcat-embedded-6/work/arquillian-tomcat-embedded-6/localhost/guvnor-webapp-5.3.0-SNAPSHOT/WEB-INF/lib/seam-persistence-api-3.1.0.Beta2.jar
      for each entry, when:
        name = "META-INF/beans.xml"
        classLoader.getResource(name) = file:/home/gdesmet/projects/jboss/forked-guvnor/guvnor-webapp/target/classes/META-INF/beans.xml // WRONG
        // Should be = .../seam-persistence-api-3.1.0.Beta2.jar!META-INF/beans.xml
      

      As a direct result, URLScanner.handle(...) handles the same wrong META-INF/beans.xml file multiple times (one for each real META-INF/beans.xml):

      Handle file META-INF/beans.xml from file:/home/gdesmet/projects/jboss/forked-guvnor/guvnor-webapp/target/classes/META-INF/beans.xml
      Handle file META-INF/beans.xml from file:/home/gdesmet/projects/jboss/forked-guvnor/guvnor-webapp/target/classes/META-INF/beans.xml
      Handle file META-INF/beans.xml from file:/home/gdesmet/projects/jboss/forked-guvnor/guvnor-webapp/target/classes/META-INF/beans.xml
      ...
      

      For more info, see this gist: https://gist.github.com/1180446

        Gliffy Diagrams

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  alesj AleŇ° Justin
                  Reporter:
                  ge0ffrey Geoffrey De Smet
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  2 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: