Index: core/src/org/netbeans/core/NbTopManager.java =================================================================== RCS file: /cvs/core/src/org/netbeans/core/NbTopManager.java,v retrieving revision 1.122 diff -u -r1.122 NbTopManager.java --- core/src/org/netbeans/core/NbTopManager.java 5 Oct 2001 16:01:40 -0000 1.122 +++ core/src/org/netbeans/core/NbTopManager.java 10 Oct 2001 15:42:45 -0000 @@ -755,7 +755,8 @@ public ClassLoader systemClassLoader () { ModuleSystem ms = getModuleSystem(); if (ms != null) { - return ms.getManager().getClassLoader(); + // #16265: do not go straight to ModuleManager + return ms.getSystemClassLoader(); } else { // This can be called very early: if lookup asks for ClassLoader. // For now, just give the startup classloader. Index: core/src/org/netbeans/core/modules/ModuleManager.java =================================================================== RCS file: /cvs/core/src/org/netbeans/core/modules/ModuleManager.java,v retrieving revision 1.14 diff -u -r1.14 ModuleManager.java --- core/src/org/netbeans/core/modules/ModuleManager.java 11 Sep 2001 20:28:37 -0000 1.14 +++ core/src/org/netbeans/core/modules/ModuleManager.java 10 Oct 2001 15:42:47 -0000 @@ -52,7 +52,8 @@ private final ModuleInstaller installer; - private SystemClassLoader classLoader = null; + private SystemClassLoader classLoader = new SystemClassLoader(new ClassLoader[0]); + private final Object classLoaderLock = "ModuleManager.classLoaderLock"; // NOI18N private final Events ev; @@ -198,41 +199,45 @@ /** Get a classloader capable of loading from any * of the enabled modules or their declared extensions. * Should be used as the result of TopManager.systemClassLoader. - * Note: must be called from within write, not - * just read, access. + * Thread-safe. * @see #PROP_CLASS_LOADER */ public ClassLoader getClassLoader() { - if (classLoader == null) { - // Set, not List, because if we have >1 bootstrap module (using Plain), - // it is likely that some of these classloaders will overlap. - Set parents = new HashSet(modules.size() * 4 / 3 + 1); // Set - Iterator it = modules.iterator(); - while (it.hasNext()) { - Module m = ((Module)it.next()); - if (! m.isEnabled()) { - continue; - } - parents.add(m.getClassLoader()); - } - ClassLoader[] parentCLs = (ClassLoader[])parents.toArray(new ClassLoader[parents.size()]); - try { - classLoader = new SystemClassLoader(parentCLs); - } catch (IllegalArgumentException iae) { - Util.err.notify(iae); - classLoader = new SystemClassLoader(new ClassLoader[0]); - } + // #16265: should not require mutex to get at. Many pieces of the IDE + // require the correct result immediately. + synchronized (classLoaderLock) { + return classLoader; } - return classLoader; } - /** Mark the current class loader as invalid. */ + /** Mark the current class loader as invalid and make a new one. */ private void invalidateClassLoader() { - if (classLoader != null) { + synchronized (classLoaderLock) { classLoader.destroy(); // probably has no effect, but just in case... - classLoader = null; - firer.change(new ChangeFirer.Change(this, PROP_CLASS_LOADER, null, null)); } + // Set, not List, because if we have >1 bootstrap module (using Plain), + // it is likely that some of these classloaders will overlap. + Set parents = new HashSet(modules.size() * 4 / 3 + 1); // Set + Iterator it = modules.iterator(); + while (it.hasNext()) { + Module m = ((Module)it.next()); + if (! m.isEnabled()) { + continue; + } + parents.add(m.getClassLoader()); + } + ClassLoader[] parentCLs = (ClassLoader[])parents.toArray(new ClassLoader[parents.size()]); + SystemClassLoader nue; + try { + nue = new SystemClassLoader(parentCLs); + } catch (IllegalArgumentException iae) { + Util.err.notify(iae); + nue = new SystemClassLoader(new ClassLoader[0]); + } + synchronized (classLoaderLock) { + classLoader = nue; + } + firer.change(new ChangeFirer.Change(this, PROP_CLASS_LOADER, null, null)); } /** A classloader giving access to all the module classloaders at once. */ Index: core/src/org/netbeans/core/modules/ModuleSystem.java =================================================================== RCS file: /cvs/core/src/org/netbeans/core/modules/ModuleSystem.java,v retrieving revision 1.10 diff -u -r1.10 ModuleSystem.java --- core/src/org/netbeans/core/modules/ModuleSystem.java 20 Jul 2001 18:12:50 -0000 1.10 +++ core/src/org/netbeans/core/modules/ModuleSystem.java 10 Oct 2001 15:42:48 -0000 @@ -131,12 +131,8 @@ } mgr.addPropertyChangeListener(new ListenerFirer()); } - mgr.mutexPrivileged().enterWriteAccess(); - try { - return mgr.getClassLoader(); - } finally { - mgr.mutexPrivileged().exitWriteAccess(); - } + // #16265: no need for write mutex any more. + return mgr.getClassLoader(); } private boolean addedClassLoaderListener = false;