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 199652 - Deadlock in EntityClassScopeAccessor
Summary: Deadlock in EntityClassScopeAccessor
Status: RESOLVED FIXED
Alias: None
Product: javaee
Classification: Unclassified
Component: Persistence (show other bugs)
Version: 7.0
Hardware: PC Linux
: P3 normal (vote)
Assignee: Sergey Petrov
URL:
Keywords: THREAD
Depends on:
Blocks:
 
Reported: 2011-06-23 11:56 UTC by Jiri Kovalsky
Modified: 2011-07-11 13:59 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Full thread dump when IDE froze during opening of Java application. (22.32 KB, text/plain)
2011-06-23 11:56 UTC, Jiri Kovalsky
Details
IDE after minimization. Just a shadow background with Open Project dialog in front. (96.26 KB, image/png)
2011-06-23 11:58 UTC, Jiri Kovalsky
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jiri Kovalsky 2011-06-23 11:56:41 UTC
Created attachment 109079 [details]
Full thread dump when IDE froze during opening of Java application.

Product Version: NetBeans IDE 7.0 (Build 201104080000)
Java: 1.6.0_26; Java HotSpot(TM) Client VM 20.1-b02
System: Linux version 2.6.35-22-generic running on i386; UTF-8; cs_CZ (nb)
Userdir: /home/cesilko/.netbeans/7.0

Shortly after classpath scanning I wanted to open an already existing Java sample application project but the IDE froze when I hit "Open Project" button. If it matters I had Debugger Core - UI and Project UI NetBeans projects already open in the IDE. I am attaching FTD and screenshot of the frozen IDE. After 10 minutes I killed the IDE.
Comment 1 Jiri Kovalsky 2011-06-23 11:58:50 UTC
Created attachment 109080 [details]
IDE after minimization. Just a shadow background with Open Project dialog in front.
Comment 2 Jesse Glick 2011-06-27 21:34:17 UTC
The interesting part:


"Parsing & Indexing Loop (201104080000)" daemon prio=10 tid=0xecb02800 nid=0xe41 in Object.wait() [0xedaf9000]
   java.lang.Thread.State: RUNNABLE
	at org.netbeans.modules.j2ee.persistence.api.EntityClassScope.<clinit>(EntityClassScope.java:71)
	at org.netbeans.modules.j2ee.jpa.model.ModelUtils.getModel(ModelUtils.java:235)

"org.netbeans.modules.project.ui.ProjectChooserAccessory$ModelUpdater" daemon prio=10 tid=0x08e0a400 nid=0xe2d in Object.wait() [0xee2fc000]
   java.lang.Thread.State: RUNNABLE
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:247)
	at org.netbeans.modules.j2ee.persistenceapi.EntityClassScopeAccessor.<clinit>(EntityClassScopeAccessor.java:61)
	at org.netbeans.modules.j2ee.persistence.spi.EntityClassScopeFactory.createEntityClassScope(EntityClassScopeFactory.java:66)


This is the usual http://wiki.apidesign.org/wiki/FriendPackages pattern, except I think misimplemented in that EntityClassScopeAccessor should not have a static block referencing EntityClassScope, because this can deadlock in the static initializers; rather, EntityClassScopeFactory.createEntityClassScope should do this Class.forName itself. I have a feeling a similar bug was reported in the past against a different module using this pattern.

BTW I am not sure what the purpose of the accessor pattern here is to begin with; if anyone can call createEntityClassScope, why not just make EntityClassScope's constructor public (or put the factory method in EntityClassScope)? The only reason I can see for this separation is to make it clear which calls are for API clients vs. for SPI clients.
Comment 3 Sergey Petrov 2011-07-08 12:32:59 UTC
Right now I'm not sure what for Class.forName is used in EntityClassScopeAccessor as result isn't used anywhere, is there any ideas?
Comment 4 Sergey Petrov 2011-07-08 12:37:47 UTC
ok, got it, to initialize "DEFAULT", no need to answer prev question.
Comment 5 Sergey Petrov 2011-07-10 11:37:06 UTC
Jesse, thanks for investigation, will move class.forName to the factory, regarding why it was implemented this way I have no ideas and I'm going to avoid bigger refactoring for now.
Comment 6 Sergey Petrov 2011-07-10 12:42:40 UTC
http://hg.netbeans.org/web-main/rev/ae827b502c30 moved
Comment 7 Quality Engineering 2011-07-11 13:59:21 UTC
Integrated into 'main-golden', will be available in build *201107110600* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main/rev/ae827b502c30
User: Sergey B. Petrov <sj-nb@netbeans.org>
Log: #199652 - move accessor initializing to factory