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

(-)a/openide.util/src/org/openide/util/lookup/MetaInfServicesLookup.java (-4 / +3 lines)
Lines 60-65 Link Here
60
import java.util.logging.Level;
60
import java.util.logging.Level;
61
import java.util.logging.Logger;
61
import java.util.logging.Logger;
62
import org.openide.util.Lookup;
62
import org.openide.util.Lookup;
63
import org.openide.util.RequestProcessor;
63
64
64
/**
65
/**
65
 * @author Jaroslav Tulach, Jesse Glick
66
 * @author Jaroslav Tulach, Jesse Glick
Lines 69-74 Link Here
69
final class MetaInfServicesLookup extends AbstractLookup {
70
final class MetaInfServicesLookup extends AbstractLookup {
70
71
71
    private static final Logger LOGGER = Logger.getLogger(MetaInfServicesLookup.class.getName());
72
    private static final Logger LOGGER = Logger.getLogger(MetaInfServicesLookup.class.getName());
73
    static final RequestProcessor RP = new RequestProcessor(MetaInfServicesLookup.class.getName(), 1);
72
    private static int knownInstancesCount;
74
    private static int knownInstancesCount;
73
    private static final List<Reference<Object>> knownInstances;
75
    private static final List<Reference<Object>> knownInstances;
74
    static {
76
    static {
Lines 118-126 Link Here
118
                // Added new class, search for it.
120
                // Added new class, search for it.
119
                LinkedHashSet<AbstractLookup.Pair<?>> arr = getPairsAsLHS();
121
                LinkedHashSet<AbstractLookup.Pair<?>> arr = getPairsAsLHS();
120
                search(c, arr);
122
                search(c, arr);
121
122
                // listeners are notified under while holding lock on class c, 
123
                // let say it is acceptable now
124
                listeners = setPairsAndCollectListeners(arr);
123
                listeners = setPairsAndCollectListeners(arr);
125
            } else {
124
            } else {
126
                // ok, nothing needs to be done
125
                // ok, nothing needs to be done
Lines 130-136 Link Here
130
129
131
        NotifyListeners notify = new NotifyListeners(listeners);
130
        NotifyListeners notify = new NotifyListeners(listeners);
132
        if (notify.shallRun()) {
131
        if (notify.shallRun()) {
133
            notify.run();
132
            RP.post(notify);
134
        }
133
        }
135
    }
134
    }
136
135
(-)a/openide.util/test/unit/src/org/openide/util/lookup/MetaInfServicesLookupTest.java (-32 / +18 lines)
Lines 62-69 Link Here
62
import java.util.Set;
62
import java.util.Set;
63
import java.util.TreeSet;
63
import java.util.TreeSet;
64
import java.util.WeakHashMap;
64
import java.util.WeakHashMap;
65
import java.util.concurrent.Executors;
65
import java.util.concurrent.atomic.AtomicBoolean;
66
import java.util.concurrent.TimeUnit;
67
import java.util.jar.JarEntry;
66
import java.util.jar.JarEntry;
68
import java.util.jar.JarOutputStream;
67
import java.util.jar.JarOutputStream;
69
import java.util.logging.Level;
68
import java.util.logging.Level;
Lines 389-427 Link Here
389
        assertGC("Class can be garbage collected", ref);
388
        assertGC("Class can be garbage collected", ref);
390
    }
389
    }
391
390
392
    public void testListenersAreNotifiedWithoutHoldingALockIssue36035() throws Exception {
391
    public void testSuperTypes() throws Exception {
393
        final Lookup l = getTestedLookup(c2);
392
        doTestSuperTypes(createLookup(c2));
394
        final Class xface = c1.loadClass("org.foo.Interface");
393
        doTestSuperTypes(new ProxyLookup(createLookup(c2)));
395
        final Lookup.Result res = l.lookup(new Lookup.Template(Object.class));
394
    }
396
395
    private void doTestSuperTypes(Lookup l) throws Exception {
397
        class L implements LookupListener, Runnable {
396
        final Class<?> xface = c1.loadClass("org.foo.Interface");
398
            private Thread toInterrupt;
397
        final Lookup.Result<Object> res = l.lookupResult(Object.class);
399
398
        assertEquals("Nothing yet", 0, res.allInstances().size());
400
            public void run() {
399
        final AtomicBoolean event = new AtomicBoolean();
401
                assertNotNull("Possible to query lookup", l.lookup(xface));
400
        final Thread here = Thread.currentThread();
402
                assertEquals("and there are two items", 2, res.allInstances().size());
401
        res.addLookupListener(new LookupListener() {
403
                toInterrupt.interrupt();
402
            public void resultChanged(LookupEvent ev) {
404
            }
403
                if (Thread.currentThread() == here) {
405
404
                    event.set(true);
406
            public synchronized void resultChanged(LookupEvent ev) {
407
                toInterrupt = Thread.currentThread();
408
                Executors.newSingleThreadScheduledExecutor().schedule(this, 0, TimeUnit.MICROSECONDS);
409
                try {
410
                    wait(3000);
411
                    fail("Should be interrupted - means it was not possible to finish query in run() method");
412
                } catch (InterruptedException ex) {
413
                    // this is what we want
414
                }
405
                }
415
            }
406
            }
416
        }
407
        });
417
        L listener = new L();
418
419
        res.addLookupListener(listener);
420
        assertEquals("Nothing yet", 0, res.allInstances().size());
421
422
        assertNotNull("Interface found", l.lookup(xface));
408
        assertNotNull("Interface found", l.lookup(xface));
423
        assertNotNull("Listener notified", listener.toInterrupt);
409
        assertFalse(event.get());
424
410
        MetaInfServicesLookup.RP.post(new Runnable() {public void run() {}}).waitFinished();
425
        assertEquals("Now two", 2, res.allInstances().size());
411
        assertEquals("Now two", 2, res.allInstances().size());
426
    }
412
    }
427
    
413
    

Return to bug 169844