This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 16265
Collapse All | Expand All

(-)core/src/org/netbeans/core/NbTopManager.java (-1 / +2 lines)
Lines 755-761 Link Here
755
    public ClassLoader systemClassLoader () {
755
    public ClassLoader systemClassLoader () {
756
        ModuleSystem ms = getModuleSystem();
756
        ModuleSystem ms = getModuleSystem();
757
        if (ms != null) {
757
        if (ms != null) {
758
            return ms.getManager().getClassLoader();
758
            // #16265: do not go straight to ModuleManager
759
            return ms.getSystemClassLoader();
759
        } else {
760
        } else {
760
            // This can be called very early: if lookup asks for ClassLoader.
761
            // This can be called very early: if lookup asks for ClassLoader.
761
            // For now, just give the startup classloader.
762
            // For now, just give the startup classloader.
(-)core/src/org/netbeans/core/modules/ModuleManager.java (-27 / +32 lines)
Lines 52-58 Link Here
52
    
52
    
53
    private final ModuleInstaller installer;
53
    private final ModuleInstaller installer;
54
    
54
    
55
    private SystemClassLoader classLoader = null;
55
    private SystemClassLoader classLoader = new SystemClassLoader(new ClassLoader[0]);
56
    private final Object classLoaderLock = "ModuleManager.classLoaderLock"; // NOI18N
56
    
57
    
57
    private final Events ev;
58
    private final Events ev;
58
    
59
    
Lines 198-238 Link Here
198
    /** Get a classloader capable of loading from any
199
    /** Get a classloader capable of loading from any
199
     * of the enabled modules or their declared extensions.
200
     * of the enabled modules or their declared extensions.
200
     * Should be used as the result of TopManager.systemClassLoader.
201
     * Should be used as the result of TopManager.systemClassLoader.
201
     * <strong>Note:</strong> must be called from within write, not
202
     * Thread-safe.
202
     * just read, access.
203
     * @see #PROP_CLASS_LOADER
203
     * @see #PROP_CLASS_LOADER
204
     */
204
     */
205
    public ClassLoader getClassLoader() {
205
    public ClassLoader getClassLoader() {
206
        if (classLoader == null) {
206
        // #16265: should not require mutex to get at. Many pieces of the IDE
207
            // Set, not List, because if we have >1 bootstrap module (using Plain),
207
        // require the correct result immediately.
208
            // it is likely that some of these classloaders will overlap.
208
        synchronized (classLoaderLock) {
209
            Set parents = new HashSet(modules.size() * 4 / 3 + 1); // Set<ClassLoader>
209
            return classLoader;
210
            Iterator it = modules.iterator();
211
            while (it.hasNext()) {
212
                Module m = ((Module)it.next());
213
                if (! m.isEnabled()) {
214
                    continue;
215
                }
216
                parents.add(m.getClassLoader());
217
            }
218
            ClassLoader[] parentCLs = (ClassLoader[])parents.toArray(new ClassLoader[parents.size()]);
219
            try {
220
                classLoader = new SystemClassLoader(parentCLs);
221
            } catch (IllegalArgumentException iae) {
222
                Util.err.notify(iae);
223
                classLoader = new SystemClassLoader(new ClassLoader[0]);
224
            }
225
        }
210
        }
226
        return classLoader;
227
    }
211
    }
228
    
212
    
229
    /** Mark the current class loader as invalid. */
213
    /** Mark the current class loader as invalid and make a new one. */
230
    private void invalidateClassLoader() {
214
    private void invalidateClassLoader() {
231
        if (classLoader != null) {
215
        synchronized (classLoaderLock) {
232
            classLoader.destroy(); // probably has no effect, but just in case...
216
            classLoader.destroy(); // probably has no effect, but just in case...
233
            classLoader = null;
234
            firer.change(new ChangeFirer.Change(this, PROP_CLASS_LOADER, null, null));
235
        }
217
        }
218
        // Set, not List, because if we have >1 bootstrap module (using Plain),
219
        // it is likely that some of these classloaders will overlap.
220
        Set parents = new HashSet(modules.size() * 4 / 3 + 1); // Set<ClassLoader>
221
        Iterator it = modules.iterator();
222
        while (it.hasNext()) {
223
            Module m = ((Module)it.next());
224
            if (! m.isEnabled()) {
225
                continue;
226
            }
227
            parents.add(m.getClassLoader());
228
        }
229
        ClassLoader[] parentCLs = (ClassLoader[])parents.toArray(new ClassLoader[parents.size()]);
230
        SystemClassLoader nue;
231
        try {
232
            nue = new SystemClassLoader(parentCLs);
233
        } catch (IllegalArgumentException iae) {
234
            Util.err.notify(iae);
235
            nue = new SystemClassLoader(new ClassLoader[0]);
236
        }
237
        synchronized (classLoaderLock) {
238
            classLoader = nue;
239
        }
240
        firer.change(new ChangeFirer.Change(this, PROP_CLASS_LOADER, null, null));
236
    }
241
    }
237
    
242
    
238
    /** A classloader giving access to all the module classloaders at once. */
243
    /** A classloader giving access to all the module classloaders at once. */
(-)core/src/org/netbeans/core/modules/ModuleSystem.java (-6 / +2 lines)
Lines 131-142 Link Here
131
            }
131
            }
132
            mgr.addPropertyChangeListener(new ListenerFirer());
132
            mgr.addPropertyChangeListener(new ListenerFirer());
133
        }
133
        }
134
        mgr.mutexPrivileged().enterWriteAccess();
134
        // #16265: no need for write mutex any more.
135
        try {
135
        return mgr.getClassLoader();
136
            return mgr.getClassLoader();
137
        } finally {
138
            mgr.mutexPrivileged().exitWriteAccess();
139
        }
140
    }
136
    }
141
    private boolean addedClassLoaderListener = false;
137
    private boolean addedClassLoaderListener = false;
142
    
138
    

Return to bug 16265