Modify the content of cache only if the iterator went through all proxy results
1.1 --- a/openide.util.lookup/src/org/openide/util/lookup/ProxyLookup.java Fri Mar 09 10:14:24 2012 +0100
1.2 +++ b/openide.util.lookup/src/org/openide/util/lookup/ProxyLookup.java Fri Mar 09 14:14:47 2012 +0100
1.3 @@ -1056,7 +1056,7 @@
1.4 Collection<Object> compute = null;
1.5 Collection<Object> ret = null;
1.6
1.7 - if (firstNonEmpty == null) {
1.8 + if (firstNonEmpty == null || firstNonEmpty[0] == 0) {
1.9 if (indexToCache == 1) {
1.10 HashSet<Object> s = new HashSet<Object>();
1.11 compute = s;
1.12 @@ -1099,7 +1099,7 @@
1.13 }
1.14 }
1.15 }
1.16 - if (i == arr.length) {
1.17 + if (i == arr.length && compute != null) {
1.18 R r = result;
1.19 if (r != null) {
1.20 r.updateResultCache(indexToCache, arr, ret);
2.1 --- a/openide.util.lookup/test/unit/src/org/openide/util/lookup/ProxyLookupTest.java Fri Mar 09 10:14:24 2012 +0100
2.2 +++ b/openide.util.lookup/test/unit/src/org/openide/util/lookup/ProxyLookupTest.java Fri Mar 09 14:14:47 2012 +0100
2.3 @@ -296,6 +296,30 @@
2.4 }
2.5 }
2.6
2.7 + public void testConfuseIterativeIterator() {
2.8 + InstanceContent ic1 = new InstanceContent();
2.9 + AbstractLookup l1 = new AbstractLookup(ic1);
2.10 + InstanceContent ic2 = new InstanceContent();
2.11 + AbstractLookup l2 = new AbstractLookup(ic2);
2.12 + InstanceContent ic3 = new InstanceContent();
2.13 + AbstractLookup l3 = new AbstractLookup(ic3);
2.14 +
2.15 + ProxyLookup pl = new ProxyLookup(l1, l2, l3);
2.16 + Result<Number> res = pl.lookupResult(Number.class);
2.17 +
2.18 + ic1.add(1);
2.19 + ic2.add(2f);
2.20 + ic3.add(3d);
2.21 +
2.22 + int cnt = 0;
2.23 + for (Number n : res.allInstances()) {
2.24 + cnt += n.intValue();
2.25 + }
2.26 + assertEquals("Six", 6, cnt);
2.27 + final Collection<? extends Number> all = res.allInstances();
2.28 + assertEquals("Three numbers: " + all, 3, all.size());
2.29 + }
2.30 +
2.31 /** Index 0 of lookups will be modified, the rest is up to the
2.32 * setup code.
2.33 */