6 Replies Latest reply on Feb 10, 2010 5:43 PM by Flavia Rainone

    Modules with null ClassLoaders

    Flavia Rainone Master

      I have just found out that ClassPoolRepository is registering null class loaders.

      JBossClDelegatingClassPoolFactory.create method has a call to registerBootstrapClassLoaders

       

      public synchronized AbstractClassPool create(ClassLoader cl, ClassPool src, ScopedClassPoolRepository repository)
         {
            if (this.currentClassLoaders.contains(cl))
            {
               return null;
            }
            currentClassLoaders.add(cl);
            try
            {
               ClassPool parent = getCreateParentClassPools(cl, src, repository);
               
               if (cl instanceof RealClassLoader)
               {
                  Module module = registry.getModule(cl);
                  if (module == null)
                  {
                     module = getModuleForClassLoader(cl);
                  }
                  registerModuleCallback.registerModule(module);
       --->           registerBootstrapLoaders(module, repository);
      ...
      }
      

       

      This is the implementation of registerBootstrapLoaders:

       

      private void registerBootstrapLoaders(Module skip, ScopedClassPoolRepository repository)
         {
            Collection<Module> unregistered = registerModuleCallback.getUnregisteredModules();
            if (unregistered.size() > 0)
            {
               for (Module module : unregistered)
               {
                  if (module == skip)
                  {
                     continue;
                  }
                  ClassLoader loader = getClassLoaderForModule(module);
                  if (this.currentClassLoaders.contains(loader))
                  {
                     continue;
                  }
                  ClassPool classPool = repository.registerClassLoader(loader);
                  if (classPool == null)
                  {
                     repository.unregisterClassLoader(loader);
                  }
               }
            }
         }
      

       

      The problem is that many of those modules, if not all, have a null class loader at this point.

       

      I'll try skipping the registration of such modules to see if any test breaks. Does anybody has a better idea on how to fix this?