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.

Bug 187642 - Endless wrapping of Collection inside ProxyLookup
Summary: Endless wrapping of Collection inside ProxyLookup
Status: RESOLVED FIXED
Alias: None
Product: platform
Classification: Unclassified
Component: Lookup (show other bugs)
Version: 6.x
Hardware: All All
: P2 normal (vote)
Assignee: Jaroslav Tulach
URL:
Keywords: PERFORMANCE
Depends on:
Blocks:
 
Reported: 2010-06-16 09:43 UTC by Petr Nejedly
Modified: 2010-06-17 03:20 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Sample application which leads to StackOverflow when using ProxyLookup (22.93 KB, application/x-zip)
2010-06-16 12:43 UTC, rudy_cortembert
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Petr Nejedly 2010-06-16 09:43:34 UTC
ProxyLookup (when assertions are enabled) guards its internals by wrapping its internal results Map with Collections.synchronizedMap.
Unluckily, it does it even during internal operations as a result of a change in delegates, so the chain of Collections.synchronizedMap grows and slows down the lookup considerably. It can also lead to stack overflows.

The problem seems to be inside RealInternalData.getResults()

The test follows:
    public void testFrequentSwitching() {
        Object o1 = new Object();
        Object o2 = new Object();
        String s1 = new String("foo");
        String s2 = new String("bar");

        Lookup l1 = Lookups.fixed(o1, s1);
        Lookup l2 = Lookups.fixed(o2, s2);

        ProxyLookup lookup = new ProxyLookup (new Lookup[0]);

        Lookup.Result<Object> res1 = lookup.lookupResult(Object.class);
        Lookup.Result<String> res2 = lookup.lookupResult(String.class);
        
        for (int i=0; i<100; i++) {
            lookup.setLookups(l1);
            lookup.setLookups(l2);
        }
        assertSize("Lookup has grown too much", 1500, lookup);
    }
Comment 1 Jaroslav Tulach 2010-06-16 11:16:02 UTC
core-main#47bc964ce54e
Comment 2 rudy_cortembert 2010-06-16 12:43:34 UTC
Created attachment 100128 [details]
Sample application which leads to StackOverflow when using ProxyLookup

This small application is based on http://blogs.sun.com/geertjan/entry/lookup_example.
Comment 3 Quality Engineering 2010-06-17 03:20:27 UTC
Integrated into 'main-golden', will be available in build *201006170001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main/rev/47bc964ce54e
User: Jaroslav Tulach <jtulach@netbeans.org>
Log: #187642: Don't wrap unmodifiableMap in another unmodifiableMap