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 249414 - java.lang.IllegalStateException: You cannot use MetaInfServicesLookup.Item[otool.maven.queries.MavenFileOwnerQueryImpl] in more than one AbstractLookup. Prev: 44 new: 44
Summary: java.lang.IllegalStateException: You cannot use MetaInfServicesLookup.Item[ot...
Status: RESOLVED FIXED
Alias: None
Product: platform
Classification: Unclassified
Component: Lookup (show other bugs)
Version: 8.0
Hardware: All All
: P2 normal (vote)
Assignee: Antonin Nebuzelsky
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-12-17 22:47 UTC by Tomas Stupka
Modified: 2015-01-31 07:57 UTC (History)
3 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
<no description> (3.12 KB, patch)
2014-12-17 22:48 UTC, Tomas Stupka
Details | Diff
Trying to simulate the problem in a test, but so far no luck (5.16 KB, patch)
2014-12-22 18:15 UTC, Jaroslav Tulach
Details | Diff
Fix + Test (51.21 KB, patch)
2015-01-20 15:42 UTC, Jaroslav Havlin
Details | Diff
Change in parsing.indexing that makes the patch work (646 bytes, patch)
2015-01-23 12:18 UTC, Jaroslav Havlin
Details | Diff
Alternative fix (51.71 KB, patch)
2015-01-23 20:22 UTC, Jaroslav Havlin
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tomas Stupka 2014-12-17 22:47:31 UTC
Product Version = NetBeans IDE Dev (Build 20141217-ccff60a1f40c)
Operating System = Mac OS X version 10.10 running on x86_64
Java; VM; Vendor = 1.7.0_65
Runtime = Java HotSpot(TM) 64-Bit Server VM 24.65-b04

occasionally an exception like the one bellow appears. 

Jarda was so nice and already provided a patch which seems to work. See attachment. 

Caused by: java.lang.IllegalStateException: You cannot use MetaInfServicesLookup.Item[otool.maven.queries.MavenFileOwnerQueryImpl] in more than one AbstractLookup. Prev: 44 new: 44
	at org.openide.util.lookup.AbstractLookup$Pair.setIndex(AbstractLookup.java:860)
	at org.openide.util.lookup.InheritanceTree$Node.assignItem(InheritanceTree.java:1178)
	at org.openide.util.lookup.InheritanceTree.add(InheritanceTree.java:198)
	at org.openide.util.lookup.InheritanceTree.add(InheritanceTree.java:122)
	at org.openide.util.lookup.DelegatingStorage.add(DelegatingStorage.java:108)
	at org.openide.util.lookup.AbstractLookup.setPairsAndCollectListeners(AbstractLookup.java:361)
	at org.openide.util.lookup.MetaInfServicesLookup.beforeLookup(MetaInfServicesLookup.java:171)
	at org.openide.util.lookup.MetaInfServicesLookup.beforeLookupResult(MetaInfServicesLookup.java:135)
	at org.openide.util.lookup.AbstractLookup.lookup(AbstractLookup.java:483)
	at org.openide.util.lookup.ProxyLookup$R.initResults(ProxyLookup.java:390)
	at org.openide.util.lookup.ProxyLookup$R.addLookupListener(ProxyLookup.java:489)
	at org.netbeans.api.project.FileOwnerQuery.<clinit>(FileOwnerQuery.java:82)
	... 24 more
Comment 1 Tomas Stupka 2014-12-17 22:48:11 UTC
Created attachment 151154 [details]
<no description>
Comment 2 Jaroslav Tulach 2014-12-22 18:15:15 UTC
Created attachment 151245 [details]
Trying to simulate the problem in a test, but so far no luck
Comment 3 Tomas Zezula 2015-01-15 13:57:45 UTC
Cannot start tailwind 4 java due to this exception.
Comment 4 Jaroslav Havlin 2015-01-20 15:42:08 UTC
Created attachment 151588 [details]
Fix + Test

Attaching a patch that contains the proposed fix and a test case (outlined by Ondra Vrabec).

Please check the patch to ensure that the test is designed correctly and that the fix won't break anything.
I'll run commit-validation soon and inform you about the results.

Thank you.
Comment 5 Jaroslav Havlin 2015-01-21 12:36:56 UTC
The commit validation fails:

 - org.netbeans.core.validation.ValidateLayerConsistencyTest
   Failure: The test shuttingDown[org.netbeans.core.validation.ValidateLayerConsistencyTest]
            did not finish in 180000ms
 - org.netbeans.core.validation.ValidateModulesTest.testConsistency 
   Error:   Timeout occurred. Please note the time in the report does not reflect the time
            until the timeout.
 - org.netbeans.core.validation.ValidateNbinstPlatformTest
   Failure: The test shuttingDown[org.netbeans.core.validation.ValidateNbinstTest] did not
            finish in 180000ms
 - org.netbeans.core.validation.ValidateNbinstTest
   Failure: The test shuttingDown[org.netbeans.core.validation.ValidateNbinstTest] did not
            finish in 180000ms
Comment 6 Jaroslav Tulach 2015-01-21 19:26:03 UTC
Didn't finish in 180s usually means deadlock.
Comment 7 Jaroslav Havlin 2015-01-23 12:18:41 UTC
Created attachment 151646 [details]
Change in parsing.indexing that makes the patch work

Attached patch fixes "bug" in parsing.indexing, which causes the freeze.
(If the @OnStop Runnable is invoked twice, it initializes a CountDownLatch
which is never decreased.)
I'll debug the code to find out why this happens now.

(In reply to Tomas Zezula from comment #3)
> Cannot start tailwind 4 java due to this exception.
A workaround has been applied to fix this problem.

The bug is quite difficult to reproduce, decreasing priority.
Comment 8 Jaroslav Havlin 2015-01-23 20:22:58 UTC
Created attachment 151654 [details]
Alternative fix

Alternative, safer patch, which fixes insertItem(Item,List) method in MetaInfServicesLookup class. Commit validation passes. Problem with multiple registrations with different positions remains (the behavior is undefined in some cases - the position of firstly retrieved service is used for all services of the provider).
Comment 9 Jaroslav Havlin 2015-01-23 20:30:19 UTC
(In reply to Jaroslav Havlin from comment #7)
> (If the @OnStop Runnable is invoked twice, it initializes a CountDownLatch
> which is never decreased.)
There were duplicate items in lookup.lookupAll(Runnable.class), as @OnStop providers implement two interfaces, Runnable and Callable, and there were lookup items for each of these definition classes.
Comment 10 Jaroslav Tulach 2015-01-26 08:05:16 UTC
(In reply to Jaroslav Havlin from comment #8)
> Created attachment 151654 [details]
> Alternative fix
> 
> Alternative, safer patch, 

It is great a failure has been demonstrated in the unit test. True, the fix of the code is really more gentle. I can confirm the new unit test fails without the fix and passes with the fix. Unless there are other failing tests outthere, I think the patch can be integrated. Good work.
Comment 11 Jaroslav Havlin 2015-01-29 16:32:36 UTC
Thank you very much, Jarda, for checking the patch.

Integrated as http://hg.netbeans.org/core-main/rev/77c64635f35a
Comment 12 Quality Engineering 2015-01-31 07:57:41 UTC
Integrated into 'main-silver', will be available in build *201501310002* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/77c64635f35a
User: Jaroslav Havlin <jhavlin@netbeans.org>
Log: #249414: IllegalStateException: You cannot use MetaInfServicesLookup.Item in more than one AbstractLookup