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 150066 - ProjectManager tends to create duplicate project instances
Summary: ProjectManager tends to create duplicate project instances
Status: RESOLVED INVALID
Alias: None
Product: projects
Classification: Unclassified
Component: Generic Infrastructure (show other bugs)
Version: 6.x
Hardware: All All
: P2 blocker (vote)
Assignee: Jiri Skrivanek
URL:
Keywords:
Depends on:
Blocks: 148288
  Show dependency tree
 
Reported: 2008-10-14 11:08 UTC by Nikita Krjukov
Modified: 2008-10-16 00:33 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 Nikita Krjukov 2008-10-14 11:08:39 UTC
The org.netbeans.api.project.ProjectManager (PM) looks like a controller, which should caching and loading projects. 
It has the function findProject(projectDirectory). It is expected (according to common sense) it provides the same
Project by the same project's folder. But unfortunately it works not very reliable way. Sometimes PM can cache more then
one instance of the same project. It can lead to unexpected errors at different places. 

Actually I faced with problem (issue #148288) which made me investigate a bit. The reason of the described problem is
the FileObject class. It doesn't redefine the equals() and hashCode() methods. The FileObject (project directory) is
used as a key in a HashSet. The HashSet (dir2Proj) is the main container for caching projects in PM.
Comment 1 Nikita Krjukov 2008-10-14 11:26:13 UTC
I tried experimenting with sources in scope of the issue #148288. I used the sources from netbeans61_fixes branch. 
It seems the same problem exists in the trunk branch. 

I think the real problem locates not in the ProjectManager but rather in the FileObject. I added (locally) equals() and
hashCode() methods to the FileObject and BaseFileObj classes and it helps in my case: 

org.openide.filesystems.FileObject;

protected static boolean equal(Object o1, Object o2) {
   if (o1 == o2) return true;
   return (o1 == null || o2 == null) ? false : o1.equals(o2);
}

@Override
public int hashCode() {
    return toString().hashCode();
}

@Override
public boolean equals(Object obj) {
    if (this == obj) return true;
    if (obj == null) return false;
    //
    if (obj instanceof FileObject) {
        String otherFile = ((FileObject)obj).toString();
        return equal(this.toString(), otherFile);
    }
    //
    return super.equals(obj);
}

org.netbeans.modules.masterfs.filebasedfs.fileobjects.BaseFileObj;

@Override
public int hashCode() {
    return this.fileName.getFile().hashCode();
}

@Override
public boolean equals(Object obj) {
    if (this == obj) return true;
    if (obj == null) return false;
    //
    if (obj instanceof BaseFileObj) {
        File otherFile = ((BaseFileObj)obj).getFileName().getFile();
        return equal(this.fileName.getFile(), otherFile);
    }
    //
    return super.equals(obj);
}

Eventually I don't insist FileObject should redefine equals method. But the ProjectManager should be smart enough to
prevent duplicate caching when it get different instances of FileObject which both pointing to the same folder. 
That is why I filed the issue to this category. 
Comment 2 Nikita Krjukov 2008-10-14 11:31:50 UTC
BTW, after my local changes with FileObject I found that Project Manager works as I expected and it seems NetBeans works
a little bit faster. Maybe it is only my feelings. Also I hope more predictable work of Project Manager can fix some
other issues which have not been found yet. 
Comment 3 Milos Kleint 2008-10-14 11:41:57 UTC
AFAIK the contract of FileObject is that as long as the FileObject is no GC-ed, always the same instance is returned for
a given file.

reassigning to filesystems
Comment 4 Jiri Skrivanek 2008-10-14 12:13:48 UTC
Could you attach some reproducable test?
Comment 5 Nikita Krjukov 2008-10-14 15:31:08 UTC
I didn't write a special test. I tried to fix the issue #148289. So you can try using the steps described there. 
Be aware that the 148289 doesn't reproduced in NetBeans 6.5. But it doesn't mean that everything Ok there. 
Please see description of the 148289
Comment 6 Nikita Krjukov 2008-10-14 16:33:44 UTC
Ask me if you have any questions with reproducing the 148289
Comment 7 Jiri Skrivanek 2008-10-15 08:40:24 UTC
I tried to follow steps in issue 148289 but when I click Mapper button it says "Unable to show bpel mapper. The bpel
mapper is not required for the (newProcess [Process]) activity.". So far, I don't know how failure on screen shot can be
connected with ProjectManager. Please, give me either unit test or steps how to reproduce the failure and pointers to
bpel code which calls ProjectManager and which is involved according to your investigation. Thank you in advance.

Product Version: NetBeans IDE 6.1 (Build 200804211638)
Java: 1.6.0_10; Java HotSpot(TM) Client VM 11.0-b15
System: Windows XP version 5.1 running on x86; Cp1250; cs_CZ (nb)
Comment 8 Nikita Krjukov 2008-10-15 11:09:34 UTC
Oh. Big sorry that I confused you. The issue number was a bit incorrect. :-(
You should use the 148288 instead. 
Comment 9 Milos Kleint 2008-10-15 12:58:49 UTC
invalid.

the most likely cause of the issue in bpel project is similar to what was happening in swing app projhect template in
issue http://www.netbeans.org/issues/show_bug.cgi?id=129405.
http://hg.netbeans.org/main/rev/e150f0d43ac6


Comment 10 Jiri Skrivanek 2008-10-15 13:28:58 UTC
I agree it should be fixed in Bpel project because other projects like J2SE or web project work without problems.
Comment 11 Nikita Krjukov 2008-10-16 00:33:42 UTC
I agree that the problem isn't clear enough. Also it is difficult to reproduce it because it doesn't appear at NetBeans
6.5 main branch. But it has not been proved that the real problem somewhere in the BPEL project. 

The bug #148288 well reproduced in the soa-dev branch, so I'm going to continue investigating and maybe reopen this
issue later if I get additional evidences.