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 119727 - Discrepancy in results of Lookup for different calls
Summary: Discrepancy in results of Lookup for different calls
Status: VERIFIED FIXED
Alias: None
Product: platform
Classification: Unclassified
Component: Lookup (show other bugs)
Version: 6.x
Hardware: All All
: P2 blocker (vote)
Assignee: Jaroslav Tulach
URL:
Keywords:
Depends on:
Blocks: 119696
  Show dependency tree
 
Reported: 2007-10-23 08:55 UTC by Petr Nejedly
Modified: 2008-12-22 12:08 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Petr Nejedly 2007-10-23 08:55:30 UTC
While debugging issue 119696, I found that the Lookup in nodes does yield different results when different calls are used.
This is the root case of the mentioned issue, as it needs to conditionally add the node into a lookup used for context
aware actions, but it uses different lookup call than the ContextAwareAction implementations.

I used the following debugging code in TreeView.TakeAction:
  Lookup contextLookup = nodes[0].getLookup ();
  System.err.println(" self type in lkp: " + contextLookup.lookup(nodes[0].getClass());
  System.err.println(" node in lkp: " + contextLookup.lookup(Node.class));
  System.err.println(" lookupResult: " + contextLookup.lookupResult(Node.class).allInstances());
and the result was, surprisingly:
 self type in lkp: org.netbeans.modules.favorites.Favorites$ProjectFilterNode@17f2faa[Name=test, displayName=test.dummy]
 node in lkp: org.netbeans.modules.favorites.Favorites$ProjectFilterNode@17f2faa[Name=test, displayName=test.dummy]
 lookupResult: []

The bug might actually be in FilterNode's lookup implementation at the end, but I'd still like to ask Yarda to look at it.
Comment 1 Jaroslav Tulach 2007-10-24 15:07:37 UTC
So far it works for me:


IDE:-------------------------------------------------
IDE: [24.10.07 16:04] Committing "FilterNodeTest.java" started
Checking in FilterNodeTest.java;
/shared/data/ccvs/repository/openide/nodes/test/unit/src/org/openide/nodes/FilterNodeTest.java,v  <--  
FilterNodeTest.java
new revision: 1.10; previous revision: 1.9
done
IDE: [24.10.07 16:05] Committing "FilterNodeTest.java" finished
Comment 2 Jaroslav Tulach 2007-10-24 15:48:50 UTC
Simulated, here is the failing test:

    public void testBuggyIsWrongInFavoritesIssue119727() {
        class ProjectFilterNode extends FilterNode {
            public ProjectFilterNode (Node node, org.openide.nodes.Children children) {
                super (node, children);
            }
        }
        
        CookieSet set = CookieSet.createGeneric(null);
        
        Node pfn = new AbstractNode(Children.LEAF, set.getLookup());
        FilterNode n = new ProjectFilterNode(pfn, Children.LEAF);

        
        Lookup contextLookup = n.getLookup();
        Object o;
        
        o = contextLookup.lookup(ProjectFilterNode.class);
        assertEquals("found self", n, o);
        
        o = contextLookup.lookup(n.getClass());
        assertEquals("found sefl2", n, o);
        
        o = contextLookup.lookup(Node.class);
        assertEquals("found node", n, o);
        
        Collection<? extends Node> all = contextLookup.lookupResult(Node.class).allInstances();
        assertEquals("One found: " + all, 1, all.size());
        assertEquals("It is the filter node", n, all.iterator().next());
    }
Comment 3 Jaroslav Tulach 2007-10-24 16:09:27 UTC
Checking in test/unit/src/org/openide/nodes/FilterNodeTest.java;
/shared/data/ccvs/repository/openide/nodes/test/unit/src/org/openide/nodes/FilterNodeTest.java,v  <--  
FilterNodeTest.java
new revision: 1.11; previous revision: 1.10
done
Checking in src/org/openide/nodes/FilterNode.java;
/shared/data/ccvs/repository/openide/nodes/src/org/openide/nodes/FilterNode.java,v  <--  FilterNode.java
new revision: 1.12; previous revision: 1.11
done
Comment 4 Petr Nejedly 2007-10-25 10:04:21 UTC
Behaves as expected now.