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 64767 - Wrong FileObject returned for anonymous members
Summary: Wrong FileObject returned for anonymous members
Status: RESOLVED WORKSFORME
Alias: None
Product: java
Classification: Unclassified
Component: Unsupported (show other bugs)
Version: 5.x
Hardware: All All
: P3 blocker (vote)
Assignee: Jan Becicka
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-09-20 18:29 UTC by _ tboudreau
Modified: 2007-09-26 09:14 UTC (History)
0 users

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 _ tboudreau 2005-09-20 18:29:21 UTC
Ran into this working on contrib/javaUsagesNavigator:

I have the Action you see below for opening a class member when the user double
clicks.  It works fine except in one case:

I have two copies of A.java - one in the project it really lives in;  the other
is a copy in another project full of junk for testing - its classes are not
resolvable, etc., but it works to test simple things and to make sure behavior
is good when there are unresolvable classes.

I am editing the valid version of A.java.  I expand usages of some method.  One
usage is in an anonymous inner class.  For *those* usages, the getDataObject()
code below returns the wrong copy of A.java - so double clicking takes me to the
invalid version.  Works fine for non-anonymous references.  The culprit code
that is returning the wrong FileObject is:
        Resource r = member.getResource();
        FileObject fob = JavaModel.getFileObject(r);

Don't know if it causes a problem for anything but my module, but I thought it
might.


    private static final class OC extends AbstractAction {
        private ClassMember member;
        public OC (ClassMember member) {
            this.member = member;
            putValue (Action.NAME, "Go To Source"); //XXX I18N
        }
    
        public void actionPerformed(ActionEvent ae) {
            try {
                DataObject d = getDataObject(member);
                if (d != null) {
                    PositionBounds bounds =
JavaMetamodel.getManager().getElementPosition(member);
                    if (bounds != null) {
                        JavaEditor ed = ((JavaEditor)
d.getCookie(JavaEditor.class));
                        ed.openAtPosition(bounds.getBegin());
                        return;
                    }
                }
            } catch (javax.jmi.reflect.InvalidObjectException e) {
            }
            Toolkit.getDefaultToolkit().beep();
        }
    }
    
    private static final DataObject getDataObject(ClassMember member) {
        Resource r = member.getResource();
        FileObject fob = JavaModel.getFileObject(r);
        if (fob != null && fob.isValid()) {
            try {
                return DataObject.find (fob);
            } catch (DataObjectNotFoundException donfe) {
                //do nothing
            }
        }
        return null;
    }
Comment 1 _ tboudreau 2005-09-20 19:42:03 UTC
Actually, it's not just anonymous members, I was wrong.  Seems pretty random. 
Don't know if it's a real problem for any code outside the usage navigator.  How
to reproduce:

CVS-up contrib/javaUsagesNavigator

Get a CVS checkout of jnn from cvs.dev.java.net
Open the project (you may need to create a freeform project for it)
Open com/sun/tools/jnn/RSSBrowser.java
create /tmp/JavaApplication1 project
Copy RSSBrowser there (don't fix the package name) and open that too
Switch to Usages in the Navigator combo box
Browse usages from the *real* RSSBrowser
Notice some usages refer to the other RSSBrowser (you can see them, they'll be
prefixed by "RSSBrowser." even though they're usages of methods in the real
RSSBrowser.

Can't figure out any pattern to when it happens.
Comment 2 Jan Becicka 2005-10-04 15:07:04 UTC
If you have two copies of the same file in two projects and Resource (or
FileObject) is sometimes returned correctly and sometimes not - it looks like
problem with classpath. What classpath do you set for your transaction? If you
don't set any, you use MergedClassPath, which holds both classpath items in
random order and this is the reason why it "randomly" works. If my assumption is
right - this issue is not a bug in javacore. You must correctly set classpath to
fix this issue. Do you explicitly set classpath for MDR transaction?
Comment 3 _ tboudreau 2005-10-04 17:51:05 UTC
My problem, not yours, then.  Thanks!
Comment 4 Quality Engineering 2007-09-20 12:01:26 UTC
Reorganization of java component