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 229366 - Save of incorrect pom.xml file leads to lose of project's documentBase
Summary: Save of incorrect pom.xml file leads to lose of project's documentBase
Status: RESOLVED WONTFIX
Alias: None
Product: projects
Classification: Unclassified
Component: Generic Infrastructure (show other bugs)
Version: 7.3
Hardware: PC Linux
: P3 normal with 2 votes (vote)
Assignee: Tomas Stupka
URL:
Keywords: 7.4_HR_FIX
: 225754 234389 (view as bug list)
Depends on: 209322
Blocks:
  Show dependency tree
 
Reported: 2013-05-05 15:25 UTC by jomu
Modified: 2016-07-07 08:39 UTC (History)
10 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Screenshot with error (30.57 KB, image/png)
2013-05-05 15:25 UTC, jomu
Details
Enterprise Application with error (197.91 KB, application/zip)
2013-05-05 15:26 UTC, jomu
Details
Solves the problems with missing source root (8.80 KB, patch)
2013-08-30 12:51 UTC, Jaroslav Tulach
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description jomu 2013-05-05 15:25:14 UTC
Created attachment 134114 [details]
Screenshot with error

After upgrading from NB 7.2 to 7.3 I could not add Java ServerFaces framework to my web application. The error message shown is "No web folder found".
Comment 1 jomu 2013-05-05 15:26:06 UTC
I was able to reproduce the bug on a maven NB 7.3 project.

Create new Maven enterprise application project
try to add framework - this will work, cancel this step

Then open pom of web application and "destroy" it -e.g. by adding

<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>     
</dependency>

Save pom, project becomes unloadable.
Add missing values and save again, project is valid again

<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>     
  <version>4.10</version>       
  <scope>test</scope>
</dependency>

Try to add framework - this will lead to the error
Comment 2 jomu 2013-05-05 15:26:58 UTC
Created attachment 134115 [details]
Enterprise Application with error
Comment 3 jomu 2013-05-05 15:27:59 UTC
Workaround: I have added the framework using NB 7.2.1. Afterwards I was able to continue editing using NB 7.3
Comment 4 jomu 2013-05-05 15:31:04 UTC
Forum thread with same issue: http://forums.netbeans.org/viewtopic.php?p=146758#146758
Comment 5 Martin Fousek 2013-05-06 05:47:45 UTC
Issue is reproducible. JSF panel doesn't find any document root and complains about that fact by the error mentioned by jomu.

I debug the WebModuleImpl of the maven module and it looks that before the save of the broken pom.xml the project has documentRoot as usually, after the save one source disappear (the one defining TYPE_DOC_ROOT) and the web project becomes broken.
Comment 6 Martin Janicek 2013-06-04 15:05:05 UTC
I believe the problem is a little bit deeper. From what I understand, the current behavior is following:

- For the new Maven Web project the LookupProviderSupport.SourcesImpl.getSourceGroups() returns correctly SourceGroup's from two registered Source's (general one MavenSourcesImpl and additional J2eeMavenSourcesImpl registered via @PSP annotation for War packaging) --> this is correct

- When breaking the project (using incomplete dependency) LookupProviderSupport.SourcesImpl.resultChanged() is called, it clear these two Source's and when the getSourceGroups() is called again, it return SourceGroup's from one registered Source (only the general one) --> this is correct because the pom is broken, we don't know packaging and thus War packaging services registered via @PSP shouldn't be present

- When fixing the project (completing dependency) LookupProviderSupport.SourcesImpl.resultChanged() is not called --> this does not seem to be correct as the Lookup should have changed (the packaging type has changed and we have to add additional services registered via @PSP for that type)

..reassigning to Project component for evaluation. Not sure who is responsible for calling resultChanged() in cases when only lookup difference is caused by @PSP ..if it's Project API job or Lookup itself.
Comment 7 Milos Kleint 2013-06-07 07:56:19 UTC
org.netbeans.spi.project.support.DelegatingLookupImpl.doDelegate() method is crucial here.

1. initially both PSP instances are created on line 130

2. both their org.netbeans.modules.projectapi.LazyLookupProviders.forProjectServiceProvider()->.beforeLookup() methods are called.

when I change packaging from war to jar the Sources merger result gets changed. Correct, the j2ee impl lookup was removed.

when I change the packaging back to war
1. the j2ee PSP instance is created on line 130
2. BUT the before lookup method is not called.

I don't have an explanation for that yet, but the lookup merger is listening on changes in the right result, so either that is not working or we have some timing issue someplace with the various levels of proxy lookups someplace.

a workaround is to restart the IDE after the problem appears
Comment 8 Milos Kleint 2013-06-17 12:48:28 UTC
related to issue 230469 maybe.
Comment 9 Milos Kleint 2013-07-24 16:54:31 UTC
probably related to issue 210481 and issue 209322
Comment 10 Milos Kleint 2013-07-25 11:06:13 UTC
reverting changeset http://hg.netbeans.org/main-golden/rev/548e5aad22d6 from issue 210481 appears to fix our issue, not sure *if* the stack overflow can appear again. It didn't for me.
Comment 11 Milos Kleint 2013-07-26 09:00:14 UTC
please evaluate  (could be related it issue 232400, but not duplicate).

the problem in org.netbeans.spi.project.support.LookupProviderSupport.SourcesImpl is that the instance doesn't get notified of changes.

delegates = lookup.lookupResult(Sources.class);
delegates.addLookupListener(this);
Comment 12 Martin Janicek 2013-08-15 12:46:22 UTC
*** Bug 225754 has been marked as a duplicate of this bug. ***
Comment 13 Martin Janicek 2013-08-15 12:49:59 UTC
*** Bug 234389 has been marked as a duplicate of this bug. ***
Comment 14 Jaroslav Tulach 2013-08-28 13:47:51 UTC
(In reply to Milos Kleint from comment #11)
> please evaluate  (could be related it issue 232400, but not duplicate).

Issue 232400 was reproducible by enabling new (e.g. JavaEE) modules and that part was fixed. However I don't see anything related to changing state of modules in this issue. As such I don't believe it is related to fix made for 232400 at all. 

If I am confused and there is some change in module state in this bug, please point that out and assign back.
Comment 15 Milos Kleint 2013-08-28 14:00:32 UTC
I haven't primarily reassigned because I believe it's a duplicate caused by the same code as issue 232400, I reassigned because the issue is a reproducible scenario where having a proxylookup delegating to multiple forPath() lookups fails to notify of changes in the lookup content for results obtained before the switch. Since I assumed the problem is not in proxylookup itself, it has to be somewhere in the forPath() code. That's why I reassigned.
Comment 16 Jaroslav Tulach 2013-08-30 10:28:42 UTC
OK, reproduced the scenario described in comment 1.
Comment 17 Jaroslav Tulach 2013-08-30 12:38:39 UTC
I believe the LazyLookupProviders ProxyLookup subclass is written a bit incorrectly. It will never notify any change by itself, it relies on somebody else to query it. That is not correct. It might have worked before issue 209322 was integrated (the ProxyLookup always recomputed completely), but it was more an accident than by design.

I'll see if I can come up with some solution.
Comment 18 Jaroslav Tulach 2013-08-30 12:51:47 UTC
Created attachment 139493 [details]
Solves the problems with missing source root
Comment 19 Jaroslav Tulach 2013-08-30 12:54:48 UTC
While the previous patch is not polished, it seems to fix the problem with missing J2ee source root. It tries to enforce refresh (previously done in beforeLookup) whenever the list of lookups we delegate to changes.

Possibly problems: 
1. some hook is instantiated more than once due to the forced refresh.
2. the refresh is done from synchronized block (as setLookups), which is potential reason for deadlocks

But I hope Miloš will be able to deal with it now, when the internal Lookup issues seem to be overcome.
Comment 20 Milos Kleint 2013-08-30 13:13:00 UTC
(In reply to Jaroslav Tulach from comment #19)
> While the previous patch is not polished, it seems to fix the problem with
> missing J2ee source root. It tries to enforce refresh (previously done in
> beforeLookup) whenever the list of lookups we delegate to changes.
> 
> Possibly problems: 
> 1. some hook is instantiated more than once due to the forced refresh.


That's more or less a deal breaker. Do I understand it correctly that the user-space instances in @psp are now re-instantiated everytime some event comes around (new module enabled, change of packaging?, etc). That's about to change the semantics of the project lookup and will definitely break things. like ProjectOpenedHook and others.
It's ok to discard instances associated with "war" packaging when the project is no longer "war" project. However the basic maven user-space instances need to persist across changes in the lookup.

Maybe we should abandon the whole lazy loading charade and just have plain Lookup.fixed() for all instances registered via @psp. Would changing the packaging (and thus lookup content) work then?
Comment 21 Milos Kleint 2013-09-02 14:25:02 UTC
(In reply to Milos Kleint from comment #20)
> (In reply to Jaroslav Tulach from comment #19)
> > While the previous patch is not polished, it seems to fix the problem with
> > missing J2ee source root. It tries to enforce refresh (previously done in
> > beforeLookup) whenever the list of lookups we delegate to changes.
> > 
> > Possibly problems: 
> > 1. some hook is instantiated more than once due to the forced refresh.
> 
> 
> That's more or less a deal breaker. Do I understand it correctly that the
> user-space instances in @psp are now re-instantiated everytime some event
> comes around (new module enabled, change of packaging?, etc). That's about
> to change the semantics of the project lookup and will definitely break
> things. like ProjectOpenedHook and others.
> It's ok to discard instances associated with "war" packaging when the
> project is no longer "war" project. However the basic maven user-space
> instances need to persist across changes in the lookup.
> 
> Maybe we should abandon the whole lazy loading charade and just have plain
> Lookup.fixed() for all instances registered via @psp. Would changing the
> packaging (and thus lookup content) work then?


I've tweaked to patch to just create the instance once per lookup (eg. global maven stuff is created once and the per packaging stuff is re-created on packaging change)

However I've also tried to just remove the entire lazy loading code and replace
it with Lookups.fixed() in @psp annotation processor. since both refresh() and createAdditionalLookup() are called on the same set of @psp instances, it's more or less the same effect with fairly less code.
Comment 22 Milos Kleint 2013-09-03 15:24:47 UTC
mjanicek has come up with a harm reduction strategy: maintain the packaging (and thus the lookup associated with it) while the project is unloadable by transferring it from the old, correct maven instance.

http://hg.netbeans.org/core-main/rev/a6f8b3a1302f

mjanicek: please verify that the fix indeed works and we can backport to release74 branch then
Comment 23 Jesse Glick 2013-09-03 15:45:04 UTC
What is the purpose of MavenProjectCache.isFallbackproject? The original NbMavenProject.isErrorPlaceholder seems more direct and reliable.
Comment 24 Martin Janicek 2013-09-04 12:08:05 UTC
Great, the fix works correctly and seems to be safe. Thanks Milosi!
Comment 25 Milos Kleint 2013-09-04 12:09:44 UTC
Ok, I will file a HR commit request.
Comment 26 Quality Engineering 2013-09-05 01:28:39 UTC
Integrated into 'main-silver', will be available in build *201309050001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/a6f8b3a1302f
User: Milos Kleint <mkleint@netbeans.org>
Log: #229366 harm reduction bugfix - attempt to carry over packaging value from previously loaded MavenProject if the current one is broken, chances are the user will eventually fix the problem and this way packaging (and lookup) stays the same.
Comment 27 Milos Kleint 2013-09-05 12:32:47 UTC
http://hg.netbeans.org/releases/rev/41581cb9229b

downgrading to P3, as the workaround applied to release74 branch significantly reduces the likelihood of the occurrence of the problem.
Comment 28 Martin Balin 2016-07-07 08:39:28 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