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 146852 - Registering external source roots in postWriteRequest is unreliable
Summary: Registering external source roots in postWriteRequest is unreliable
Alias: None
Product: projects
Classification: Unclassified
Component: Ant Project (show other bugs)
Version: 4.x
Hardware: All All
: P2 blocker (vote)
Assignee: Jesse Glick
: 142938 154263 (view as bug list)
Depends on: 165149
  Show dependency tree
Reported: 2008-09-10 22:04 UTC by Jesse Glick
Modified: 2009-05-19 00:31 UTC (History)
4 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:

Start of a patch (8.57 KB, patch)
2008-09-10 22:31 UTC, Jesse Glick
Details | Diff
Desired patch (3.54 KB, patch)
2009-01-09 18:14 UTC, Jesse Glick
Details | Diff
Updated patch (24.24 KB, patch)
2009-03-20 22:06 UTC, Jesse Glick
Details | Diff
Running patch... still working on this, expect to commit soon (70.06 KB, patch)
2009-04-01 22:04 UTC, Jesse Glick
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jesse Glick 2008-09-10 22:04:51 UTC
SourcesHelper.registerExternalSourceRoots Javadoc states:

"You may _not_ call this method inside the project's constructor, as it requires the actual project to exist and be
registered in ProjectManager. Typically you would use Mutex.postWriteRequest to run it later, if you were creating the
helper in your constructor, since the project construction normally occurs in read access."

Unfortunately using pWR results in strange threading behavior, including unreliable tests (see #b5f07b919bea and
#abb8ce297ad9 for example).

Perhaps this weirdness could be avoided if the SourcesHelper constructor took an optional Project object (with the
understanding that it need not yet be registered in ProjectManager). Then it would not need to find the Project from the
AntProjectHelper, which would make it possible to register the external source roots synchronously.
Comment 1 Jesse Glick 2008-09-10 22:31:37 UTC
Created attachment 69591 [details]
Start of a patch
Comment 2 Jesse Glick 2008-09-10 22:32:21 UTC
Has been a problem since the creation of SourcesHelper.
Comment 3 David Konecny 2008-09-10 23:25:54 UTC
Well, if that's all what needs to be done to resolve this issue then I wonder why have not we done it earlier. Patch
looks good to me. Thanks Jesse.
Comment 4 Jesse Glick 2008-09-11 22:38:42 UTC
I would love to have this in 6.5, but if not, then I will need to work around the timing in the Eclipse project
importer: after creating a new j2seproject (or web project), it cannot immediately use ProjectClassPathModifier, as
external roots will not yet be owned; it needs to delay this action using postWriteRequest (to run after the
Comment 5 David Konecny 2008-09-11 22:45:13 UTC
Let's fix it for 6.5. Have you intentionally passed it to Milan or would you implement it yourself Jesse? If you
introduce new API I'm happy to update Web/J2EE projects separately.
Comment 6 Jesse Glick 2008-09-12 17:43:54 UTC
I just passed it to Milan as default owner and to get a review. I don't mind doing the work but it seems too late to
make a change like this for 6.5, isn't it?
Comment 7 Jesse Glick 2008-09-12 19:00:26 UTC
Actually it seems that this is not such a high priority; in the case of the Eclipse project import, the roots are
actually registered inside the call to J2SEProjectGenerator.createProject, since we are running all this in write access:

	at org.openide.util.Mutex.leaveImpl(
	at org.openide.util.Mutex.leave(
	at org.openide.util.Mutex.readAccess(
	at org.openide.util.Mutex$
	at org.openide.util.Mutex.doWrapperAccess(
	at org.openide.util.Mutex.readAccess(
	at org.netbeans.api.project.ProjectManager.findProject(
	at org.openide.util.Mutex.writeAccess(
	at org.openide.util.Mutex$
	at org.openide.util.Mutex.doWrapperAccess(
	at org.openide.util.Mutex.writeAccess(

There seems to be some other problem making Eclipse import with external roots be broken, but I am still investigating
what that might be.
Comment 8 Jesse Glick 2009-01-09 18:06:08 UTC
*** Issue 142938 has been marked as a duplicate of this issue. ***
Comment 9 Jesse Glick 2009-01-09 18:13:40 UTC
Lack of this seems to prevent a simple-looking patch to projectimport.eclipse.core from working (an AE is thrown similar
to issue #142938 when you try to import a project). I will attach that patch here.
Comment 10 Jesse Glick 2009-01-09 18:14:42 UTC
Created attachment 75644 [details]
Desired patch
Comment 11 Antonin Nebuzelsky 2009-03-20 16:19:56 UTC
Reassigning to Jesse.
Comment 12 Jesse Glick 2009-03-20 22:06:39 UTC
Created attachment 78555 [details]
Updated patch
Comment 13 Jesse Glick 2009-03-20 22:08:14 UTC
Please review.
Comment 14 Jesse Glick 2009-04-01 22:04:33 UTC
Created attachment 79246 [details]
Running patch... still working on this, expect to commit soon
Comment 15 Jesse Glick 2009-04-02 22:39:18 UTC
core-main #23a442bff758
Comment 16 Quality Engineering 2009-04-03 20:00:45 UTC
Integrated into 'main-golden', will be available in build *200904031400* on (upload may still be in progress)
User: Jesse Glick <>
Log: Issue #146852: accept Project in a constructor for SourcesHelper to permit registerExternalRoots to run synch.
Can help simplify tests, and makes control flow easier to understand and debug.
Also taking advantage of synchronous control flow to optimize class loading in the Eclipse importer.
Comment 17 Jesse Glick 2009-04-17 17:19:33 UTC
*** Issue 154263 has been marked as a duplicate of this issue. ***