12 Replies Latest reply on Oct 12, 2007 10:33 AM by Kabir Khan

    Scoped domain with java2ParentDelegation=false loads class f

    Kabir Khan Master

      Adrian,

      I am having some slight problems with the new classloaders in head.

      aop-scopedextender-base-loaded.sar is deployed in the default classloader domain
      aop-scopedextender-child-noparentdelegation.sar is deployed with the following config:

       <loader-repository>
       aop.loading:loader=scopedextender1
       <loader-repository-config>java2ParentDelegation=false</loader-repository-config>
       </loader-repository>
      


      Both sars have a copy of org.jboss.test.aop.scopedextender.BaseAspect. Now when I try to load up BaseAspect using the "scoped" domain, it loads it up from the parent/default domain instead despite java2ParentDelegation being set to false?
      2007-10-11 21:11:33,515 TRACE [org.jboss.classloader.spi.base.BaseClassLoaderDomain] ClassLoaderDomain@bd40ef{aop.loading:loader=scopedextender1} findLoader org/jboss/test/aop/scopedextender/BaseAspect.class classLoader=null allExports=true
      2007-10-11 21:11:33,515 TRACE [org.jboss.classloader.spi.ClassLoaderDomain] ClassLoaderDomain@bd40ef{aop.loading:loader=scopedextender1} org/jboss/test/aop/scopedextender/BaseAspect.class does NOT match parent beforeFilter=NOTHING_BUT_JAVA
      2007-10-11 21:11:33,515 TRACE [org.jboss.classloader.spi.base.BaseClassLoaderDomain] ClassLoaderDomain@bd40ef{aop.loading:loader=scopedextender1} trying to load org/jboss/test/aop/scopedextender/BaseAspect.class from all exports of package org.jboss.test.aop.scopedextender null
      2007-10-11 21:11:33,515 TRACE [org.jboss.classloader.spi.ClassLoaderDomain] ClassLoaderDomain@bd40ef{aop.loading:loader=scopedextender1} org/jboss/test/aop/scopedextender/BaseAspect.class matches parent afterFilter=<EVERYTHING>
      2007-10-11 21:11:33,515 TRACE [org.jboss.classloader.spi.ClassLoaderDomain] ClassLoaderDomain@bd40ef{aop.loading:loader=scopedextender1} load from parent org/jboss/test/aop/scopedextender/BaseAspect.class parent=ClassLoaderDomain@87cd5c{<DEFAULT>}
      2007-10-11 21:11:33,515 TRACE [org.jboss.classloader.spi.base.BaseClassLoaderDomain] ClassLoaderDomain@87cd5c{<DEFAULT>} findLoader org/jboss/test/aop/scopedextender/BaseAspect.class classLoader=null allExports=true
      2007-10-11 21:11:33,515 TRACE [org.jboss.classloader.spi.ClassLoaderDomain] ClassLoaderDomain@87cd5c{<DEFAULT>} org/jboss/test/aop/scopedextender/BaseAspect.class matches parent beforeFilter=<EVERYTHING>
      2007-10-11 21:11:33,515 TRACE [org.jboss.classloader.spi.ClassLoaderDomain] ClassLoaderDomain@87cd5c{<DEFAULT>} load from parent org/jboss/test/aop/scopedextender/BaseAspect.class parent=org.jboss.system.NoAnnotationURLClassLoader@56c3cf
      2007-10-11 21:11:33,515 TRACE [org.jboss.classloader.plugins.loader.ClassLoaderToLoaderAdapter] Resource org/jboss/test/aop/scopedextender/BaseAspect.class NOT found in org.jboss.system.NoAnnotationURLClassLoader@56c3cf
      2007-10-11 21:11:33,515 TRACE [org.jboss.classloader.spi.base.BaseClassLoaderDomain] ClassLoaderDomain@87cd5c{<DEFAULT>} found in global class cache org/jboss/test/aop/scopedextender/BaseAspect.class
      2007-10-11 21:11:33,515 TRACE [org.jboss.classloader.spi.base.BaseClassLoader] BaseClassLoader@19cac0d attemptLock Thread[RMI TCP Connection(9)-127.0.0.1,5,RMI Runtime]
      2007-10-11 21:11:33,515 TRACE [org.jboss.classloader.spi.base.BaseClassLoader] BaseClassLoader@19cac0d locked Thread[RMI TCP Connection(9)-127.0.0.1,5,RMI Runtime] holding=1
      2007-10-11 21:11:33,531 TRACE [org.jboss.classloader.spi.filter.FilteredDelegateLoader] FilteredDelegateLoader@18f50ff{delegate=VFSClassLoaderPolicy@e3be9f} org.jboss.test.aop.scopedextender.BaseAspect matches class filter=[org.jboss.test.aop.scopedextender, aop-scopedextender-base.jar.META-INF, META-INF, aop-scopedextender-base.aop.META-INF, aop-scopedextender-base.jar.org.jboss.test.aop.scopedextender]
      2007-10-11 21:11:33,531 TRACE [org.jboss.classloader.spi.base.BaseClassLoader] BaseClassLoader@19cac0d load class locally org.jboss.test.aop.scopedextender.BaseAspect
      2007-10-11 21:11:33,531 TRACE [org.jboss.classloader.spi.base.BaseClassLoader] BaseClassLoader@19cac0d already loaded class org.jboss.test.aop.scopedextender.BaseAspect{cl=BaseClassLoader@19cac0d codeSource=(vfsfile:/C:/cygwin/home/Kabir/sourcecontrol/jboss-head/testsuite/output/lib/aop-scopedextender-base-loaded.sar <no signer certificates>)}
      2007-10-11 21:11:33,531 TRACE [org.jboss.classloader.spi.base.BaseClassLoader] BaseClassLoader@19cac0d unlock Thread[RMI TCP Connection(9)-127.0.0.1,5,RMI Runtime] holding=1
      




        • 1. Re: Scoped domain with java2ParentDelegation=false loads cla
          Kabir Khan Master

          Looking at the ClassLoaderDomain in a debugger, it has the expected classloader in its classLoaders list, and it is using the AFTER ParentPolicy

          • 2. Re: Scoped domain with java2ParentDelegation=false loads cla
            Kabir Khan Master

            For some reason the ClassLoaderDomain.globalResourceBlackList contains org/jboss/test/aop/scopedextender/BaseAspect.class.

            • 3. Re: Scoped domain with java2ParentDelegation=false loads cla
              Adrian Brock Master

              The ClassLoaderMetaData/Module doesn't currently provide a mechanism to
              turn off caching and blacklisting on the VFSClassLoaderPolicy.

              The actual features of the ClassLoaderMetaData is not yet complete.

              If you don't want to implement it (it's scheduled for RC1) then you
              can always hack a version of the classloader policy that turns off caching
              and blacklisting for your tests.

              • 4. Re: Scoped domain with java2ParentDelegation=false loads cla
                Kabir Khan Master

                ClassLoaderDomain.getResource() called on the scoped domain always seems to return null for any resource, and also blacklists it:

                 ClassLoaderDomain myDomain = getClassLoaderDomain();
                 URL blah = myDomain.getResource("org/jboss/test/aop/scopedextender/blah.txt"); //This file definitely exists
                 System.out.println("---- FOUND blah.txt " + blah);
                


                yields

                2007-10-12 11:33:46,015 TRACE [org.jboss.classloader.spi.base.BaseClassLoaderDomain] ClassLoaderDomain@11b3435{aop.loading:loader=scopedextender1} trying to get resource org/jboss/test/aop/scopedextender/blah.txt from all exports null
                2007-10-12 11:34:10,906 TRACE [org.jboss.classloader.spi.ClassLoaderDomain] ClassLoaderDomain@11b3435{aop.loading:loader=scopedextender1} org/jboss/test/aop/scopedextender/blah.txt matches parent afterFilter=<EVERYTHING>
                2007-10-12 11:34:10,921 TRACE [org.jboss.classloader.spi.ClassLoaderDomain] ClassLoaderDomain@11b3435{aop.loading:loader=scopedextender1} get resource from parent org/jboss/test/aop/scopedextender/blah.txt parent=ClassLoaderDomain@1f21056{<DEFAULT>}
                2007-10-12 11:34:10,921 TRACE [org.jboss.classloader.spi.ClassLoaderDomain] ClassLoaderDomain@1f21056{<DEFAULT>} org/jboss/test/aop/scopedextender/blah.txt matches parent beforeFilter=<EVERYTHING>
                2007-10-12 11:34:10,921 TRACE [org.jboss.classloader.spi.ClassLoaderDomain] ClassLoaderDomain@1f21056{<DEFAULT>} get resource from parent org/jboss/test/aop/scopedextender/blah.txt parent=org.jboss.system.NoAnnotationURLClassLoader@56c3cf
                2007-10-12 11:34:10,921 TRACE [org.jboss.classloader.plugins.loader.ClassLoaderToLoaderAdapter] Resource org/jboss/test/aop/scopedextender/blah.txt NOT found in org.jboss.system.NoAnnotationURLClassLoader@56c3cf
                2007-10-12 11:34:10,921 TRACE [org.jboss.classloader.spi.ClassLoaderDomain] ClassLoaderDomain@1f21056{<DEFAULT>} resource not found in parent org/jboss/test/aop/scopedextender/blah.txt parent=org.jboss.system.NoAnnotationURLClassLoader@56c3cf
                2007-10-12 11:34:10,921 TRACE [org.jboss.classloader.spi.base.BaseClassLoaderDomain] ClassLoaderDomain@1f21056{<DEFAULT>} trying to get resource org/jboss/test/aop/scopedextender/blah.txt from all exports [VFSClassLoaderPolicy@c1a0a6]
                2007-10-12 11:34:10,921 TRACE [org.jboss.classloader.spi.filter.FilteredDelegateLoader] FilteredDelegateLoader@d63b75{delegate=VFSClassLoaderPolicy@c1a0a6} org/jboss/test/aop/scopedextender/blah.txt matches resource filter=[org.jboss.test.aop.scopedextender, aop-scopedextender-base.jar.META-INF, META-INF, aop-scopedextender-base.aop.META-INF, aop-scopedextender-base.jar.org.jboss.test.aop.scopedextender]
                2007-10-12 11:34:10,921 TRACE [org.jboss.classloader.spi.base.BaseClassLoader] BaseClassLoader@1b28af8 get resource locally org/jboss/test/aop/scopedextender/blah.txt
                2007-10-12 11:34:10,937 TRACE [org.jboss.classloader.spi.base.BaseClassLoader] org.jboss.classloader.spi.base.BaseClassLoader$2@d9be5a resource not found locally org/jboss/test/aop/scopedextender/blah.txt
                2007-10-12 11:34:11,156 TRACE [org.jboss.classloader.spi.ClassLoaderDomain] ClassLoaderDomain@1f21056{<DEFAULT>} org/jboss/test/aop/scopedextender/blah.txt does NOT match parent afterFilter=<NOTHING>
                2007-10-12 11:34:11,156 TRACE [org.jboss.classloader.spi.ClassLoaderDomain] ClassLoaderDomain@11b3435{aop.loading:loader=scopedextender1} resource not found in parent org/jboss/test/aop/scopedextender/blah.txt parent=ClassLoaderDomain@1f21056{<DEFAULT>}
                2007-10-12 11:34:18,453 INFO [STDOUT] ---- FOUND blah.txt null
                


                The problem seems to be that no loaders are able to load up the org.jboss.test.aop.scopedextender package:
                 private URL getResourceFromExports(BaseClassLoader classLoader, String name, boolean trace)
                 {
                ...
                 String packageName = ClassLoaderUtils.getResourcePackageName(name);
                 List<ClassLoaderInformation> list = classLoadersByPackageName.get(packageName); //This returns null
                 if (trace)
                 log.trace(this + " trying to get resource " + name + " from all exports " + list);
                 if (list != null && list.isEmpty() == false)
                 {
                ...
                 }
                 // Here is not found in the exports so can we blacklist it?
                 if (canBlackList)
                 globalResourceBlackList.add(name);
                 return null;
                 }
                


                Digging into this a bit, when registering the BaseClassLoader with the scoped domain there are no packages being registered since these are null in the BaseClassLoader's underlying VFSClassLoaderPolicy.packageNames.
                 void registerClassLoader(BaseClassLoader classLoader)
                 {
                 ...
                 ClassLoaderInformation info = new ClassLoaderInformation(classLoader, policy, order++);
                 classLoaders.add(info);
                 infos.put(classLoader, info);
                
                 // Index the packages
                 String[] packageNames = policy.getPackageNames();
                 if (packageNames != null && info.getExported() != null) //both of these are null
                 {
                 ...
                 }
                


                My AS trunk is pretty out of date, so I will try refreshing that

                • 5. Re: Scoped domain with java2ParentDelegation=false loads cla
                  Adrian Brock Master

                  The second part of your comment doesn't make sense.
                  I think you are confusing explicit exports (named packages)
                  with the "exportAll" behaviour (packages are discovered from a scan of the deployment
                  classpath).

                  It is clearly trying to load to resource from the classloader and not finding it:

                  
                  Trying all classloaders in the domain
                  
                  2007-10-12 11:34:10,921 TRACE [org.jboss.classloader.spi.base.BaseClassLoaderDomain] ClassLoaderDoma
                  in@1f21056{<DEFAULT>} trying to get resource org/jboss/test/aop/scopedextender/blah.txt from all exports [VFSClassLoader
                  Policy@c1a0a6]
                  
                  This one matches.
                  
                  2007-10-12 11:34:10,921 TRACE [org.jboss.classloader.spi.filter.FilteredDelegateLoader] FilteredDele
                  gateLoader@d63b75{delegate=VFSClassLoaderPolicy@c1a0a6} org/jboss/test/aop/scopedextender/blah.txt m
                  atches resource filter=[org.jboss.test.aop.scopedextender, aop-scopedextender-base.jar.META-INF, MET
                  A-INF, aop-scopedextender-base.aop.META-INF, aop-scopedextender-base.jar.org.jboss.test.aop.scopedex
                  tender]
                  
                  Tries to find it using the VFS
                  
                  2007-10-12 11:34:10,921 TRACE [org.jboss.classloader.spi.base.BaseClassLoader] BaseClassLoader@1b28a
                  f8 get resource locally org/jboss/test/aop/scopedextender/blah.txt
                  
                  Not found!
                  
                  2007-10-12 11:34:10,937 TRACE [org.jboss.classloader.spi.base.BaseClassLoader] org.jboss.classloader
                  .spi.base.BaseClassLoader$2@d9be5a resource not found locally org/jboss/test/aop/scopedextender/blah
                  .txt
                  


                  Like I said earlier, hack the policy to turn off the blacklisting and caching,
                  but this is clearly irrelevant if it can't find the resource in the first place.

                  The code to find the resource is:

                  
                   @Override
                   public URL getResource(String path)
                   {
                   VirtualFile child = findChild(path);
                   if (child != null)
                   {
                   try
                   {
                   return child.toURL();
                   }
                   catch (Exception ignored)
                   {
                   log.trace("Error determining URL for " + child, ignored);
                   return null;
                   }
                   }
                   return null;
                   }
                  
                   /**
                   * Find a child from a path
                   *
                   * @param path the path
                   * @return the child if found in the roots
                   */
                   protected VirtualFile findChild(String path)
                   {
                   for (VirtualFile root : roots)
                   {
                   try
                   {
                   return root.findChild(path);
                   }
                   catch (Exception ignored)
                   {
                   // not found
                   }
                   }
                   return null;
                   }
                  


                  with the "roots" coming from the determineAllPackages() for "exportAll",
                  you can see this result in the filter of logging above.

                  • 6. Re: Scoped domain with java2ParentDelegation=false loads cla
                    Adrian Brock Master

                     

                    "adrian@jboss.org" wrote:

                    with the "roots" coming from the determineAllPackages() for "exportAll",
                    you can see this result in the filter of logging above.


                    Well actually you can't, but you can guess what they are from the packages found. :-)

                    • 7. Re: Scoped domain with java2ParentDelegation=false loads cla
                      Kabir Khan Master

                       

                      "adrian@jboss.org" wrote:
                      The second part of your comment doesn't make sense.
                      I think you are confusing explicit exports (named packages)
                      with the "exportAll" behaviour (packages are discovered from a scan of the deployment
                      classpath).

                      It is clearly trying to load to resource from the classloader and not finding


                      Both sars contain the same packages. Only the scoped one contains the blah.txt.

                      This is trying to load it from the correct child domain.
                      2007-10-12 11:33:46,015 TRACE [org.jboss.classloader.spi.base.BaseClassLoaderDomain] ClassLoaderDoma
                      in@11b3435{aop.loading:loader=scopedextender1} trying to get resource org/jboss/test/aop/scopedexten
                      der/blah.txt from all exports null
                      

                      The rest of the logging seems to be trying to load from a parent (which does not have the resource)
                      2007-10-12 11:34:10,906 TRACE [org.jboss.classloader.spi.ClassLoaderDomain] ClassLoaderDomain@11b343
                      5{aop.loading:loader=scopedextender1} org/jboss/test/aop/scopedextender/blah.txt matches parent afte
                      rFilter=<EVERYTHING>
                      2007-10-12 11:34:10,921 TRACE [org.jboss.classloader.spi.ClassLoaderDomain] ClassLoaderDomain@11b343
                      5{aop.loading:loader=scopedextender1} get resource from parent org/jboss/test/aop/scopedextender/bla
                      h.txt parent=ClassLoaderDomain@1f21056{<DEFAULT>}
                      


                      For the domain, when registering classloaders the packages are added correctly. For the scoped domain, they are not

                      • 8. Re: Scoped domain with java2ParentDelegation=false loads cla
                        Adrian Brock Master

                        Ok, your problem looks to be that your domain doesn't have any classloaders:

                        No classloaders in this domain (the null)
                        
                        2007-10-12 11:33:46,015 TRACE [org.jboss.classloader.spi.base.BaseClassLoaderDomain] ClassLoaderDoma
                        in@11b3435{aop.loading:loader=scopedextender1} trying to get resource org/jboss/test/aop/scopedexten
                        der/blah.txt from all exports null
                        
                        So load from parent
                        
                        2007-10-12 11:34:10,906 TRACE [org.jboss.classloader.spi.ClassLoaderDomain] ClassLoaderDomain@11b343
                        5{aop.loading:loader=scopedextender1} org/jboss/test/aop/scopedextender/blah.txt matches parent afte
                        rFilter=<EVERYTHING>
                        
                        The parent has a classloader.
                        
                        2007-10-12 11:34:10,921 TRACE [org.jboss.classloader.spi.base.BaseClassLoaderDomain] ClassLoaderDoma
                        in@1f21056{<DEFAULT>} trying to get resource org/jboss/test/aop/scopedextender/blah.txt from all exports [VFSClassLoader
                        Policy@c1a0a6]
                        


                        So the question is why is there no classloader policies in
                        aop.loading:loader=scopedextender1

                        You'll need to look at the deployment trace logging to see whether (and when)
                        the classloader gets added to the domain or whether it is getting added to the
                        wrong domain.

                        • 9. Re: Scoped domain with java2ParentDelegation=false loads cla
                          Kabir Khan Master

                          The underlying policy when registering a loader with the DEFAULT domain has
                          -exportAll=ExportAll
                          -exportedPackages contain the packages exported (probably from some scan?)

                          The underlying policy when registering a loader with the scoped domain has
                          -exportAll=null
                          -exportedPackages is null

                          I think this is the problem rather than being able to turn off blacklisting. The resources from the scoped domain are being ignored

                          • 10. Re: Scoped domain with java2ParentDelegation=false loads cla
                            Adrian Brock Master

                            The problem is in the hack class:
                            jboss-head/system-jmx/src/main/org/jboss/system/deployers/HackClassloaderMetaDataDeployer.java

                            When it creates the ClassLoaderMetaData from the old loader repository config,
                            it should be specifying exportAll=ExportAll.NON_EMPTY and importAll=true
                            for backwards compatibility.

                            I've fixed this in head if you do an svn update of system-jmx.

                            • 11. Re: Scoped domain with java2ParentDelegation=false loads cla
                              Kabir Khan Master

                              The following modification helps

                              Index: C:/cygwin/home/Kabir/sourcecontrol/jboss-head/system-jmx/src/main/org/jboss/system/deployers/HackClassloaderMetaDataDeployer.java
                              ===================================================================
                              --- C:/cygwin/home/Kabir/sourcecontrol/jboss-head/system-jmx/src/main/org/jboss/system/deployers/HackClassloaderMetaDataDeployer.java (revision 66088)
                              +++ C:/cygwin/home/Kabir/sourcecontrol/jboss-head/system-jmx/src/main/org/jboss/system/deployers/HackClassloaderMetaDataDeployer.java (working copy)
                              @@ -32,6 +32,7 @@
                               import org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer;
                               import org.jboss.deployers.structure.spi.DeploymentUnit;
                               import org.jboss.deployers.structure.spi.classloading.ClassLoaderMetaData;
                              +import org.jboss.deployers.structure.spi.classloading.ExportAll;
                               import org.jboss.mx.loading.LoaderRepositoryFactory.LoaderRepositoryConfig;
                               import org.jboss.system.metadata.ServiceDeployment;
                              
                              @@ -101,6 +102,7 @@
                               }
                               boolean useParentFirst = Boolean.valueOf(java2ParentDelegation).booleanValue();
                               metaData.setJ2seClassLoadingCompliance(useParentFirst);
                              + metaData.setExportAll(ExportAll.NON_EMPTY);
                              
                               unit.addAttachment(ClassLoaderMetaData.class, metaData);
                               }
                              


                              • 12. Re: Scoped domain with java2ParentDelegation=false loads cla
                                Kabir Khan Master

                                lol I did not see your reply