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 51810 - SourcesHelper.registerExternalRoots should be called only when a project is opened, not upon loading
Summary: SourcesHelper.registerExternalRoots should be called only when a project is o...
Status: RESOLVED WONTFIX
Alias: None
Product: projects
Classification: Unclassified
Component: Generic Infrastructure (show other bugs)
Version: 4.x
Hardware: All All
: P3 blocker (vote)
Assignee: Tomas Stupka
URL:
Keywords:
: 58058 (view as bug list)
Depends on:
Blocks: 54557 58058
  Show dependency tree
 
Reported: 2004-11-24 15:26 UTC by Jesse Glick
Modified: 2016-07-07 08:37 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Suggested patch for freeform project type (4.10 KB, patch)
2008-11-12 18:01 UTC, Jesse Glick
Details | Diff
Add-on patch using _CONFIRMED (7.55 KB, patch)
2008-11-17 20:08 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 2004-11-24 15:26:39 UTC
For predictability of behavior (at the expense of
accuracy), probably SH.rER should only be called
when a project is opened, not when it is just
loaded. Perhaps an unregister method should exist
as well, to be called when the project is closed.

This should be done for all project types.

We may also consider introducing a new
FileOwnerQuery.EXTERNAL_ALGORITHM_*, such as
EXTERNAL_ALGORITHM_PRIVATE_CACHE - caching known
external roots in the user directory (as a
Map<URL,URL>). This would enable us to leave
SH.rER in the project load code, but switch to the
new algorithm. FOQ would then check for a given
root, as it moved up the tree:

1. Is it a project dir? [as now]

2. Is it registered as an external root? [as now]

3. Is it suspected to be an external root,
according to the cache, but not yet registered in
memory? If so, try to load the project at the
cached location, and check again whether the
folder is registered as an external root. [added]

The benefit would be that you would only "miss" an
external root owner if the owning project had
never been loaded by this user, which we can
assume is pretty rare.
Comment 1 David Konecny 2005-01-24 13:43:33 UTC
Jesse, I'm moving project infrastructure  base freeform issues to you.
Comment 2 Jesse Glick 2005-01-24 21:37:12 UTC
No longer feasible for E.
Comment 3 Milos Kleint 2007-01-03 06:36:29 UTC
is this something we want to do for 6.0?
Comment 4 Milos Kleint 2008-07-03 07:55:35 UTC
I don't think this is relevant anymore. please reopen if you disagree.
Comment 5 Milos Kleint 2008-07-03 08:02:18 UTC
wf
Comment 6 Jesse Glick 2008-07-03 14:55:09 UTC
I do think we need to rework our handling of external roots. I don't know if these particular suggestions are the right
approach.
Comment 7 Jesse Glick 2008-11-12 17:59:43 UTC
Please reevaluate. The current behavior is known to cause serious problems for JDK developers, who have multiple
projects using the same external source root.

To reproduce:

1. Run IDE on a fresh user dir.

2. Open Project, and browse to the make/netbeans/ subdir of the http://hg.openjdk.java.net/jdk7/jdk7/langtools repo.

3. Select the different project items in turn, but open "compiler".

4. Move the selection around in the Projects tab over source files and watch the Main Window title. Sometimes you can
see non-"compiler" projects considered "selected" now.

5. Otherwise, browse under "Build files" and select e.g. "javap" under "netbeans". Now go back and select some source
files (in editor or Projects) - you will see "javap" in the main window.

The patch I will attach to freeform projects is simple seems to cure the problem: external source root associations are
done predictably when the project is opened. If more than one project is opened and they all claim the same root, the
last to be opened "wins", which is predictable enough.

An alternate fix would be for FileOwnerQuery to collect all projects which claim to own a given external root, giving
preference to the open project if just one, else the last to be registered. But I prefer the simplicity and
predictability of this patch (which would of course also need to done in other project types).
Comment 8 Jesse Glick 2008-11-12 18:01:19 UTC
Created attachment 73691 [details]
Suggested patch for freeform project type
Comment 9 Jan Lahoda 2008-11-17 18:09:28 UTC
The proposed patch does not seem correct to me - I think it would cause serious regressions. For example, consider
projects A and B. A is opened and depends on B. B is a freeform project, is not opened (i.e. its OpenProjectHook was not
called) and has external source roots. After the patch, it seems that no project based query (ClassPath,
FileEncodingQuery, etc.) will answer correctly for the external source roots. This can result into incorrect error
badges, data loss (a file loaded and saved using incorrect encoding), etc.
Comment 10 Jesse Glick 2008-11-17 18:29:23 UTC
If B has _never_ been opened then it is correct that queries on B's external source root will not report any project
ownership. If you have ever opened B, then the IDE will remember its association. The same is already true in case b.jar
is externally located. I consider this behavior preferable to the current behavior whereby an external source root may
be silently assigned to a project you have never even opened, which is known (not just hypothetically) to cause serious
problems.

A possible intermediate solution: besides the (now incorrectly-named) EXTERNAL_ALGORITHM_TRANSIENT, introduce e.g.
EXTERNAL_ALGORITHM_CONFIRMED. The behavior would be identical, except that a _CONFIRMED registration would trump a
_TRANSIENT registration: just keep a WeakSet<URI> listing external roots whose ownership has been confirmed, and in
markExternalOwnerTransient, if the URI is in this set and _TRANSIENT is called, then do nothing. Then change project
types to register _TRANSIENT eagerly as now, and then _CONFIRMED upon opening.
Comment 11 Jan Lahoda 2008-11-17 18:45:59 UTC
Well, but if B does not work because it was not opened yet, it seems to break the basic principle that the projects
should behave in the same way regardless they are opened or not. This seems to me like quite confusing behavior.
Comment 12 Jesse Glick 2008-11-17 19:18:07 UTC
1. It is already the case that you need to open a project at least once in case its build artifacts are externally
located. Otherwise the IDE cannot possibly know where the project is!

2. You only need to open the project _once_ (in a given userdir) for the IDE to know about it.

3. I should point out that java.source already fails to correctly scan nonopen projects (even without external roots):
issue #136522, in which you said that support for non-open projects was "best-effort only".

That said, EXTERNAL_ALGORITHM_CONFIRMED would I think address your use case while fixing the OpenJDK problem. I could
prototype and test it (against langtools) if there is interest.
Comment 13 Jan Lahoda 2008-11-17 19:28:44 UTC
I have nothing against _CONFIRMED. Also, it is true that the external source roots do not work very well now (and your
statements are correct). I only think that the attached patch makes the situation even more unpredictable (for the
user), and that certain things that work today would stop to work after the patch.
Comment 14 Jesse Glick 2008-11-17 20:08:40 UTC
Created attachment 73836 [details]
Add-on patch using _CONFIRMED
Comment 15 Milos Kleint 2008-11-18 12:07:32 UTC
looks generally ok (both as concept and implementation)
only i'm a bit concerned about the backward compatibility and the way how projects that use the new method will coexist
with those that didn't upgrade to CONFIRMED level on project opening.
Bot it could be just nitpicking, the relevant project types are few.
Comment 16 Jesse Glick 2008-11-18 18:41:42 UTC
"I'm [...] concerned [...] how projects that use the new method will coexist with those that didn't upgrade to CONFIRMED
level on project opening" - well, in the unlikely case that a project of old type claims the same external source root
as a project of new type, this just means that if you open the new-type project, close it, then open the old-type
project, the source root will still be associated with the closed project - which is what happens already, i.e. not a
regression. Not sure if there are other cases we're not thinking of.
Comment 17 Milos Kleint 2008-11-19 12:32:10 UTC
*** Issue 58058 has been marked as a duplicate of this issue. ***
Comment 18 Antonin Nebuzelsky 2010-03-29 14:10:02 UTC
Change of default owner.
Comment 19 Jesse Glick 2010-03-30 22:14:39 UTC
Probably too risky for 6.9.
Comment 20 Martin Balin 2016-07-07 08:37:03 UTC
This old bug may not be relevant anymore. If you can still reproduce it in 8.2 development builds please reopen this issue.

Thanks for your cooperation,
NetBeans IDE 8.2 Release Boss