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.
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; }
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.
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?
My problem, not yours, then. Thanks!
Reorganization of java component