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 246953 - @ProjectServiceProvider randomly not found in project's lookup
Summary: @ProjectServiceProvider randomly not found in project's lookup
Status: RESOLVED FIXED
Alias: None
Product: projects
Classification: Unclassified
Component: Generic Infrastructure (show other bugs)
Version: 8.1
Hardware: PC Linux
: P3 normal (vote)
Assignee: Tomas Stupka
URL:
Keywords: RANDOM
: 245785 249786 (view as bug list)
Depends on:
Blocks: 248599
  Show dependency tree
 
Reported: 2014-09-09 15:18 UTC by Tomas Mysik
Modified: 2015-06-04 14:48 UTC (History)
8 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter: 211715


Attachments
dumped lookup of the project (3.38 KB, text/plain)
2014-09-09 15:18 UTC, Tomas Mysik
Details
stacktrace (3.50 KB, text/plain)
2014-09-17 07:39 UTC, Vladimir Riha
Details
stacktrace (8.93 KB, text/plain)
2014-09-26 11:38 UTC, Vladimir Riha
Details
stacktrace (6.80 KB, text/plain)
2014-10-07 10:08 UTC, Exceptions Reporter
Details
stacktrace (3.54 KB, text/plain)
2014-10-07 18:48 UTC, adithyank
Details
stacktrace (3.55 KB, text/plain)
2014-10-10 20:48 UTC, Martin Entlicher
Details
Proper synchronization when creating the instances (13.01 KB, patch)
2014-10-22 11:16 UTC, Jaroslav Tulach
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tomas Mysik 2014-09-09 15:18:15 UTC
Created attachment 149092 [details]
dumped lookup of the project

I have added a unit test for it [1] but no success, unfortunately it works like a charm. But randomly I am not able to lookup my class from a project's lookup, I get 'null' (on some IDE run it works but fails on another).

The code where it fails for me is not pushed yet - please, let me know if I can help you somehow or if you need it.

Attaching assert error message with dumped lookup of the project (the class is really not there).

Thanks a lot!
[1] http://hg.netbeans.org/web-main/rev/e999dc74bd88

Product Version: NetBeans IDE Dev (Build 20140909-5e6369b32644)
Java: 1.7.0_67; Java HotSpot(TM) 64-Bit Server VM 24.65-b04
Runtime: Java(TM) SE Runtime Environment 1.7.0_67-b01
System: Linux version 3.13.0-35-generic running on amd64; UTF-8; cs_CZ (nb)
Comment 1 Tomas Mysik 2014-09-09 16:20:57 UTC
One - maybe important - note: If the class is not found in the project's lookup, it is _before_ projectOpened hook (the assertion error is not thrown in my other code which is called in this hook).

Thanks.
Comment 2 Jaroslav Tulach 2014-09-12 07:57:55 UTC
The dump of the lookup is sort of anonymous, isn't it? Following change should make it better: http://hg.netbeans.org/ergonomics/rev/ca57ea0bae57 - you can cherry pick it, if you want it today in web-main.
Comment 3 Jaroslav Tulach 2014-09-12 08:08:35 UTC
When running the e999dc74bd88 test with my toString changes I can see:

ProxyLookup(class=class org.netbeans.spi.project.support.DelegatingLookupImpl)->[SingletonLookup[org.netbeans.spi.project.ui.support.UILookupMergerSupport$ProjectProblemsProviderImpl@1f795d6], ExcludingLookup: ProxyLookup(class=class org.netbeans.spi.project.support.DelegatingLookupImpl$UnmergedLookup)->[LazyLookupProviders.LookupProvider[service=org.netbeans.modules.web.clientproject.ClientSideProjectTest$MySupport, class=org.netbeans.modules.web.clientproject.ClientSideProjectTest$MySupport, orig=MultiFileObject@f37b08[Projects/org-netbeans-modules-web-clientproject/Lookup/org-netbeans-modules-web-clientproject-ClientSideProjectTest$MySupport.instance]], LazyLookupProviders.LookupProvider[service=org.netbeans.modules.web.clientproject.spi.platform.ClientProjectEnhancedBrowserProvider, class=org.netbeans.modules.web.clientproject.browser.ClientProjectEnhancedBrowserProviderImpl, orig=MultiFileObject@1516062[Projects/org-netbeans-modules-web-clientproject/Lookup/org-netbeans-modules-web-clientproject-browser-ClientProjectEnhancedBrowserProviderImpl.instance]], .... no other LazyLookupProviders...


which of these is supposed to be the NodeJsSupport? Or is that part of not yet pushed code? Maybe put it on a branch?
Comment 4 Tomas Mysik 2014-09-12 08:19:44 UTC
NodeJs project service provider is in another module (javascript.nodejs), see [1] (sorry, was not sure how to create unit test for it properly, so I created just MySupport class in the unit tests).

Thanks.
[1] http://hg.netbeans.org/web-main/file/tip/javascript.nodejs/src/org/netbeans/modules/javascript/nodejs/platform/NodeJsSupport.java
Comment 5 Vladimir Riha 2014-09-17 07:39:11 UTC
Created attachment 149282 [details]
stacktrace

creating new HTML5 project, all default
Comment 6 Vladimir Riha 2014-09-26 11:38:06 UTC
Created attachment 149536 [details]
stacktrace

Happened on IDE start up with single JS Library project with NodeJS support and downloaded NodeJS sources.
Comment 7 Exceptions Reporter 2014-10-04 08:05:21 UTC
This bug already has 5 duplicates 
see http://statistics.netbeans.org/exceptions/detail.do?id=211715
Comment 8 Exceptions Reporter 2014-10-07 10:08:59 UTC
Created attachment 149759 [details]
stacktrace

AssertionError
Comment 9 adithyank 2014-10-07 18:48:00 UTC
Created attachment 149773 [details]
stacktrace

while opening netbeans, this exception came
Comment 10 Martin Entlicher 2014-10-10 20:48:29 UTC
Created attachment 149843 [details]
stacktrace

Created Samples > HTML5 > Knockout.js must-play games project. Run it and restarted NetBeans.
This exception was thrown after restart and the Knockout.js must-play games project disappeared from Projects window.
Comment 11 Tomas Mysik 2014-10-22 09:25:30 UTC
EDT (creation):

"AWT-EventQueue-0"
org.netbeans.modules.javascript.nodejs.file.PackageJson.<clinit>(PackageJson.java:94)
org.netbeans.modules.javascript.nodejs.platform.NodeJsSupport.<init>(NodeJsSupport.java:94)
org.netbeans.modules.javascript.nodejs.platform.NodeJsSupport.create(NodeJsSupport.java:99)
sun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethodAccessorImpl.java)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:606)
org.netbeans.modules.projectapi.LazyLookupProviders.loadPSPInstance(LazyLookupProviders.java:205)
org.netbeans.modules.projectapi.LazyLookupProviders.access$000(LazyLookupProviders.java:73)
org.netbeans.modules.projectapi.LazyLookupProviders$1$1.beforeLookup(LazyLookupProviders.java:118)
org.openide.util.lookup.ProxyLookup.lookup(ProxyLookup.java:214)
org.openide.util.lookup.ProxyLookup.lookup(ProxyLookup.java:222)
org.openide.util.lookup.ExcludingLookup.lookup(ExcludingLookup.java:142)
org.openide.util.lookup.ProxyLookup.lookup(ProxyLookup.java:222)
org.netbeans.modules.javascript.nodejs.platform.NodeJsSupport.forProject(NodeJsSupport.java:107)
org.netbeans.modules.javascript.nodejs.platform.NodeJsPlatformProvider.isEnabled(NodeJsPlatformProvider.java:112)
org.netbeans.modules.web.clientproject.api.platform.PlatformProvider.isEnabled(PlatformProvider.java:139)
org.netbeans.modules.web.clientproject.ClientSideProject.getPlatformProviders(ClientSideProject.java:460)
org.netbeans.modules.web.clientproject.ui.action.command.PlatformCommand.getSupportedActions(PlatformCommand.java:100)
org.netbeans.modules.web.clientproject.ui.action.ClientSideProjectActionProvider.getSupportedActions(ClientSideProjectActionProvider.java:129)
org.netbeans.modules.project.ui.actions.ActionsUtil.commandSupported(ActionsUtil.java:182)
org.netbeans.modules.project.ui.actions.ActionsUtil.getProjectsFromLookup(ActionsUtil.java:102)
org.netbeans.modules.project.ui.actions.MainProjectAction.selection(MainProjectAction.java:178)
org.netbeans.modules.project.ui.actions.MainProjectAction.access$000(MainProjectAction.java:74)
org.netbeans.modules.project.ui.actions.MainProjectAction$2.run(MainProjectAction.java:195)
org.netbeans.modules.project.ui.actions.MainProjectAction.refreshView(MainProjectAction.java:226)
org.netbeans.modules.project.ui.actions.MainProjectAction.refresh(MainProjectAction.java:244)
org.netbeans.modules.project.ui.actions.LookupSensitiveAction.doRefresh(LookupSensitiveAction.java:197)
org.netbeans.modules.project.ui.actions.LookupSensitiveAction.isEnabled(LookupSensitiveAction.java:139)
org.netbeans.modules.project.ui.actions.MainProjectAction.isEnabled(MainProjectAction.java:74)
org.openide.awt.Actions$ButtonBridge.updateState(Actions.java:1124)
org.openide.awt.Actions$Bridge.addNotify(Actions.java:909)
org.openide.awt.Actions$Bridge$VisL.propertyChange(Actions.java:947)
java.beans.PropertyChangeSupport.fire(PropertyChangeSupport.java:335)
java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:327)
java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:263)
java.awt.Component.firePropertyChange(Component.java:8393)
javax.swing.JComponent.addNotify(JComponent.java:4753)
java.awt.Container.addNotify(Container.java:2769)
javax.swing.JComponent.addNotify(JComponent.java:4752)
org.openide.awt.ToolbarWithOverflow.addNotify(ToolbarWithOverflow.java:201)
org.openide.awt.Toolbar.addNotify(Toolbar.java:175)
java.awt.Container.addNotify(Container.java:2769)
javax.swing.JComponent.addNotify(JComponent.java:4752)
org.netbeans.core.windows.view.ui.toolbars.ToolbarContainer.addNotify(ToolbarContainer.java:168)
java.awt.Container.addNotify(Container.java:2769)
javax.swing.JComponent.addNotify(JComponent.java:4752)
java.awt.Container.addNotify(Container.java:2769)
javax.swing.JComponent.addNotify(JComponent.java:4752)
java.awt.Container.addNotify(Container.java:2769)
javax.swing.JComponent.addNotify(JComponent.java:4752)
java.awt.Container.addNotify(Container.java:2769)
javax.swing.JComponent.addNotify(JComponent.java:4752)
java.awt.Container.addNotify(Container.java:2769)
javax.swing.JComponent.addNotify(JComponent.java:4752)
java.awt.Container.addNotify(Container.java:2769)
javax.swing.JComponent.addNotify(JComponent.java:4752)
javax.swing.JRootPane.addNotify(JRootPane.java:756)
java.awt.Container.addNotify(Container.java:2769)
java.awt.Window.addNotify(Window.java:770)
java.awt.Frame.addNotify(Frame.java:487)
java.awt.Window.show(Window.java:1031)
java.awt.Component.show(Component.java:1655)
java.awt.Component.setVisible(Component.java:1607)
java.awt.Window.setVisible(Window.java:1014)
org.netbeans.core.windows.view.ui.MainWindow.setVisible(MainWindow.java:461)
org.netbeans.core.windows.view.DefaultView.showWindowSystem(DefaultView.java:597)
org.netbeans.core.windows.view.DefaultView.windowSystemVisibilityChanged(DefaultView.java:542)
org.netbeans.core.windows.view.DefaultView.changeGUI(DefaultView.java:187)
org.netbeans.core.windows.ViewRequestor.dispatchRequest(ViewRequestor.java:275)
org.netbeans.core.windows.ViewRequestor.processVisibilityRequest(ViewRequestor.java:264)
org.netbeans.core.windows.ViewRequestor.postVisibilityRequest(ViewRequestor.java:201)
org.netbeans.core.windows.ViewRequestor.scheduleRequest(ViewRequestor.java:121)
org.netbeans.core.windows.Central.setVisible(Central.java:140)
org.netbeans.core.windows.WindowManagerImpl.setVisible(WindowManagerImpl.java:931)
org.netbeans.core.windows.WindowSystemImpl.show(WindowSystemImpl.java:105)
org.netbeans.core.GuiRunLevel$InitWinSys.run(GuiRunLevel.java:244)
java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:312)
java.awt.EventQueue.dispatchEventImpl(EventQueue.java:733)
java.awt.EventQueue.access$200(EventQueue.java:103)
java.awt.EventQueue$3.run(EventQueue.java:694)
java.awt.EventQueue$3.run(EventQueue.java:692)
java.security.AccessController.doPrivileged(AccessController.java)
java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
java.awt.EventQueue.dispatchEvent(EventQueue.java:703)
org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:159)
java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
java.awt.EventDispatchThread.run(EventDispatchThread.java:91)

Query:
"org.netbeans.modules.project.ui.actions.LookupSensitiveAction"
org.netbeans.modules.javascript.nodejs.platform.NodeJsSupport.forProject(NodeJsSupport.java:108)
org.netbeans.modules.javascript.nodejs.platform.NodeJsPlatformProvider.isEnabled(NodeJsPlatformProvider.java:112)
org.netbeans.modules.web.clientproject.api.platform.PlatformProvider.isEnabled(PlatformProvider.java:139)
org.netbeans.modules.web.clientproject.ClientSideProject.getPlatformProviders(ClientSideProject.java:460)
org.netbeans.modules.web.clientproject.ui.action.command.PlatformCommand.getSupportedActions(PlatformCommand.java:100)
org.netbeans.modules.web.clientproject.ui.action.ClientSideProjectActionProvider.getSupportedActions(ClientSideProjectActionProvider.java:129)
org.netbeans.modules.project.ui.actions.ActionsUtil.commandSupported(ActionsUtil.java:182)
org.netbeans.modules.project.ui.actions.ActionsUtil.getProjectsFromLookup(ActionsUtil.java:102)
org.netbeans.modules.project.ui.actions.MainProjectAction.selection(MainProjectAction.java:178)
org.netbeans.modules.project.ui.actions.MainProjectAction.access$000(MainProjectAction.java:74)
org.netbeans.modules.project.ui.actions.MainProjectAction$2.run(MainProjectAction.java:195)
org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:1423)
org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:2033)

Thanks.
Comment 12 Jaroslav Tulach 2014-10-22 10:37:01 UTC
LazyLookupProviders line 117 is wrong. It marks the lookup as being "filled in" while the thread continues to run. Otherthreads like in above example skip the check and return empty values meanwhile.
Comment 13 Jaroslav Tulach 2014-10-22 10:37:39 UTC
Should be relatively easy to fix. May cause deadlocks a while...
Comment 14 Jaroslav Tulach 2014-10-22 11:16:53 UTC
Created attachment 150050 [details]
Proper synchronization when creating the instances
Comment 15 Jaroslav Tulach 2014-10-22 11:17:47 UTC
Tomáši, please verify. Tomáši, please integrate.
Comment 16 Tomas Mysik 2014-10-22 11:46:32 UTC
Adding Tomas to CC.
Comment 17 Tomas Stupka 2014-10-22 12:38:16 UTC
jarda thanks!

will integrate asap

tomasi - please let me know if jardas fix helped
Comment 18 Tomas Zezula 2014-10-22 12:44:02 UTC
TZ01:
....
try {
107	                                    LOCK.wait();
108	                                } catch (InterruptedException ex) {
109	                                    LOG.log(Level.INFO, null, ex);
110	                                }
....

Isn't it dangerous in respect of possible deadlocks?
The thread may already hold some locks.
Comment 19 Jaroslav Tulach 2014-10-22 14:10:01 UTC
(In reply to Tomas Zezula from comment #18)
> Isn't it dangerous in respect of possible deadlocks?

Right, the likehood of deadlock is increased. That is why I want Tomáš Stupka to review the change, so he knows what is coming...

In general we have three options in case the service is requested by two parallel threads:

#1 - return null in the thread that comes later, but returns sooner than the initializing thread constructs the instance

#2 - let the later thread inicialize second instance

#3 - block the later thread until the first thread finishes constructing its instance

The current state is #1 and it is not ideal (otherwise Tomáš Myšík would not report this bug) as callers into Lookup cannot rely on getting registered instance. 

I offered #2 to Tomáš M. and he was not really happy with it either. It is not comfortable for people who register instances into lookup to be ready for multiple instances being created.

So my patch offers #3 - it is most comfortable for the users of the API and SPI. Its slightly higher deadlock potential can be mitigated by making constructors of the SPI objects lightweight - e.g. just assign this.project = project and leave the rest of the initialization for later.
Comment 20 Tomas Zezula 2014-10-22 14:19:40 UTC
OK, sounds good to me.
Comment 21 Tomas Stupka 2014-10-24 18:49:01 UTC
well, now i know whats coming ...

fixed in core-main #4dcd39560de8
Comment 22 Tomas Mysik 2014-10-27 07:17:38 UTC
So far, so good.

Product Version: NetBeans IDE Dev (Build 20141027-5bf8aca1355f)
Java: 1.7.0_72; Java HotSpot(TM) 64-Bit Server VM 24.72-b04
Runtime: Java(TM) SE Runtime Environment 1.7.0_72-b14
System: Linux version 3.13.0-37-generic running on amd64; UTF-8; cs_CZ (nb)
Comment 23 Tomas Stupka 2014-10-27 10:11:17 UTC
*** Bug 245785 has been marked as a duplicate of this bug. ***
Comment 24 Quality Engineering 2014-10-29 11:43:09 UTC
Integrated into 'main-silver', will be available in build *201410290913* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/ca57ea0bae57
User: Jaroslav Tulach <jtulach@netbeans.org>
Log: Give lookup created via LazyLookupProviders reasonable toString. In an attempt to investigate #246953.
Comment 25 Martin Entlicher 2015-06-04 14:48:10 UTC
*** Bug 249786 has been marked as a duplicate of this bug. ***