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 149013
Collapse All | Expand All

(-)a/o.n.bootstrap/src/org/netbeans/ProxyClassLoader.java (-38 / +23 lines)
Lines 227-233 Link Here
227
                if (shouldDelegateResource(path, null)) cls = systemCL.loadClass(name);
227
                if (shouldDelegateResource(path, null)) cls = systemCL.loadClass(name);
228
            }*/
228
            }*/
229
        } else {
229
        } else {
230
            cls = doLoadClassFromParents(del, path, pkg, name, cls);
230
            // multicovered package, search in order
231
            for (ProxyClassLoader pcl : parents) { // all our accessible parents
232
                if (del.contains(pcl) && shouldDelegateResource(path, pcl)) { // that cover given package
233
                    Class _cls = pcl.selfLoadClass(pkg, name);
234
                    if (_cls != null) {
235
                        if (cls == null) {
236
                            cls = _cls;
237
                        } else if (cls != _cls) {
238
                            String message = "Will not load class " + name + " arbitrarily from one of " +
239
                                    cls.getClassLoader() + " and " + pcl + " starting from " + this +
240
                                    "; see http://wiki.netbeans.org/DevFaqModuleCCE";
241
                            ClassNotFoundException cnfe = new ClassNotFoundException(message);
242
                            if (LOGGER.isLoggable(Level.FINE)) {
243
                                LOGGER.log(Level.FINE, null, cnfe);
244
                            } else {
245
                                LOGGER.warning(message);
246
                            }
247
                            throw cnfe;
248
                        }
249
                    }
250
                }
251
            }
231
            if (cls == null && del.contains(this)) cls = selfLoadClass(pkg, name); 
252
            if (cls == null && del.contains(this)) cls = selfLoadClass(pkg, name); 
232
            if (cls != null) sclPackages.put(pkg, false); 
253
            if (cls != null) sclPackages.put(pkg, false); 
233
        }
254
        }
Lines 235-247 Link Here
235
            try {
256
            try {
236
                cls = systemCL.loadClass(name);
257
                cls = systemCL.loadClass(name);
237
            } catch (ClassNotFoundException e) {
258
            } catch (ClassNotFoundException e) {
238
                cls = doLoadClassFromParents(null, path, pkg, name, cls);
259
                throw new ClassNotFoundException(diagnosticCNFEMessage(e.getMessage(), del), e);
239
                if (cls == null) {
240
                    cls = selfLoadClass(pkg, name);
241
                    if (cls == null) {
242
                        throw new ClassNotFoundException(diagnosticCNFEMessage(e.getMessage(), del), e);
243
                    }
244
                }
245
            }
260
            }
246
        }
261
        }
247
        if (cls == null) {
262
        if (cls == null) {
Lines 271-303 Link Here
271
                " and declared parents " + parentSetS;
286
                " and declared parents " + parentSetS;
272
    }
287
    }
273
288
274
    private Class doLoadClassFromParents(Set<ProxyClassLoader> del, final String path, String pkg, String name, Class cls) throws ClassNotFoundException {
275
        // multicovered package, search in order
276
        for (ProxyClassLoader pcl : parents) { // all our accessible parents
277
             if (del == null || (del.contains(pcl) && shouldDelegateResource(path, pcl))) {
278
                // that cover given package
279
                Class _cls = pcl.selfLoadClass(pkg, name);
280
                if (_cls != null) {
281
                    if (cls == null) {
282
                        cls = _cls;
283
                    } else if (cls != _cls) {
284
                        String message = "Will not load class " + name + " arbitrarily from one of " +
285
                                cls.getClassLoader() + " and " + pcl + " starting from " + this +
286
                                "; see http://wiki.netbeans.org/DevFaqModuleCCE";
287
                        ClassNotFoundException cnfe = new ClassNotFoundException(message);
288
                        if (LOGGER.isLoggable(Level.FINE)) {
289
                            LOGGER.log(Level.FINE, null, cnfe);
290
                        } else {
291
                            LOGGER.warning(message);
292
                        }
293
                        throw cnfe;
294
                    }
295
                }
296
            }
297
        }
298
        return cls;
299
    }
300
301
    /** May return null */ 
289
    /** May return null */ 
302
    private synchronized Class selfLoadClass(String pkg, String name) { 
290
    private synchronized Class selfLoadClass(String pkg, String name) { 
303
        Class cls = findLoadedClass(name); 
291
        Class cls = findLoadedClass(name); 
Lines 393-401 Link Here
393
381
394
        // uncovered package, go directly to SCL
382
        // uncovered package, go directly to SCL
395
        if (url == null && shouldDelegateResource(path, null)) url = systemCL.getResource(name);
383
        if (url == null && shouldDelegateResource(path, null)) url = systemCL.getResource(name);
396
        if (url == null) {
397
            url = findResource(name);
398
        }
399
        
384
        
400
        return url;
385
        return url;
401
    }
386
    }
(-)a/o.n.bootstrap/test/unit/src/org/netbeans/ModuleFactoryAlienTest.java (-7 / +18 lines)
Lines 172-178 Link Here
172
    }
172
    }
173
173
174
    public static class Factory extends ModuleFactory {
174
    public static class Factory extends ModuleFactory {
175
        private static Set<String> registered;
176
175
177
        static void clear() {
176
        static void clear() {
178
        }
177
        }
Lines 355-361 Link Here
355
        }
354
        }
356
355
357
        @Override
356
        @Override
358
        @SuppressWarnings(value = "unchecked")
359
        public Enumeration<URL> findResources(String name) {
357
        public Enumeration<URL> findResources(String name) {
360
            return Enumerations.empty();
358
            return Enumerations.empty();
361
        }
359
        }
Lines 365-376 Link Here
365
            if (name.equals("org.fakepkg.FakeIfce")) {
363
            if (name.equals("org.fakepkg.FakeIfce")) {
366
                return FakeIfceHidden.class;
364
                return FakeIfceHidden.class;
367
            }
365
            }
368
            try {
366
            return null;
369
                return l == null ? null : l.loadClass(name);
367
        }
370
            } catch (ClassNotFoundException ex) {
368
371
                ex.printStackTrace();
369
        @Override
372
                return null;
370
        protected synchronized Class loadClass(String name, boolean resolve) throws ClassNotFoundException {
371
            Class c = findLoadedClass(name);
372
            if (c != null) {
373
                return c;
373
            }
374
            }
375
            if (l != null) {
376
                try {
377
                    c = l.loadClass(name);
378
                    if (resolve) {
379
                        resolveClass(c);
380
                    }
381
                    return c;
382
                } catch (ClassNotFoundException x) {}
383
            }
384
            return super.loadClass(name, resolve);
374
        }
385
        }
375
386
376
        @Override
387
        @Override
(-)a/o.n.bootstrap/test/unit/src/org/netbeans/ProxyClassLoaderTest.java (-13 / +21 lines)
Lines 49-56 Link Here
49
import java.util.Arrays;
49
import java.util.Arrays;
50
import java.util.Collections;
50
import java.util.Collections;
51
import java.util.Enumeration;
51
import java.util.Enumeration;
52
import java.util.HashSet;
53
import java.util.Set;
54
import org.fakepkg.FakeIfceHidden;
52
import org.fakepkg.FakeIfceHidden;
55
import org.openide.util.Enumerations;
53
import org.openide.util.Enumerations;
56
import org.openide.util.Exceptions;
54
import org.openide.util.Exceptions;
Lines 196-206 Link Here
196
194
197
            ClassLoader l;
195
            ClassLoader l;
198
196
199
            public Loader(String publicPackage) throws MalformedURLException {
197
            public Loader(String... publicPackages) throws MalformedURLException {
200
                super(new ClassLoader[0], true);
198
                super(new ClassLoader[0], true);
201
                Set<String> pkgs = new HashSet<String>();
199
                addCoveredPackages(Arrays.asList(publicPackages));
202
                pkgs.add(publicPackage);
203
                addCoveredPackages(pkgs);
204
            }
200
            }
205
201
206
            @Override
202
            @Override
Lines 214-220 Link Here
214
            }
210
            }
215
211
216
            @Override
212
            @Override
217
            @SuppressWarnings(value = "unchecked")
218
            public Enumeration<URL> findResources(String name) {
213
            public Enumeration<URL> findResources(String name) {
219
                return Enumerations.empty();
214
                return Enumerations.empty();
220
            }
215
            }
Lines 224-235 Link Here
224
                if (name.equals("org.fakepkg.FakeIfce")) {
219
                if (name.equals("org.fakepkg.FakeIfce")) {
225
                    return FakeIfceHidden.class;
220
                    return FakeIfceHidden.class;
226
                }
221
                }
227
                try {
222
                return null;
228
                    return l == null ? null : l.loadClass(name);
223
            }
229
                } catch (ClassNotFoundException ex) {
224
230
                    ex.printStackTrace();
225
            @Override
231
                    return null;
226
            protected synchronized Class loadClass(String name, boolean resolve) throws ClassNotFoundException {
227
                Class c = findLoadedClass(name);
228
                if (c != null) {
229
                    return c;
232
                }
230
                }
231
                if (l != null) {
232
                    try {
233
                        c = l.loadClass(name);
234
                        if (resolve) {
235
                            resolveClass(c);
236
                        }
237
                        return c;
238
                    } catch (ClassNotFoundException x) {}
239
                }
240
                return super.loadClass(name, resolve);
233
            }
241
            }
234
242
235
            @Override
243
            @Override
Lines 241-247 Link Here
241
        File j1 = new File(jars, "simple-module.jar");
249
        File j1 = new File(jars, "simple-module.jar");
242
        ClassLoader l1 = new URLClassLoader(new URL[] { j1.toURI().toURL() });
250
        ClassLoader l1 = new URLClassLoader(new URL[] { j1.toURI().toURL() });
243
251
244
        Loader loader = new Loader("org.bar");
252
        Loader loader = new Loader("org.bar", "org.fakepkg");
245
        File jar = new File(jars, "depends-on-simple-module.jar");
253
        File jar = new File(jars, "depends-on-simple-module.jar");
246
        loader.l = new URLClassLoader(new URL[] { jar.toURI().toURL() }, l1);
254
        loader.l = new URLClassLoader(new URL[] { jar.toURI().toURL() }, l1);
247
255

Return to bug 149013