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.
Petre yesterday I was trying to resolve issue 39944 and issue 39783 by calling the fold maintainers directly instead of posting to RP (when pane.setDocument() is called and the view hierarchy is being constructed which in turn triggers the fold hierarchy to be created). It looked well until Mato hit a dedlok (attached). I guess that happened when the IDE was shutdown with few editors opened and Mato restarted the IDE and "scrolled" through opened components by Alt+Right key. That deadlock unveils an interesting case that makes me think about the assigning of the document to the text component. In the current state the situation may be like this: 1) document gets created in CES. 2) document loading gets scheduled into RP. 3) before doc-loading RP write-locks the doc the AWT thread constructs the editor pane and calls CES.getDocumentHack() and assigns the doc into pane by pane.setDocument(). 4) setDocument() triggers various listeners (e.g. in TextUI) that service the doc change - e.g. view hierarchy gets created etc. Those operations typically run under read/write lock being held on the document to make sure there is no modification done to the doc during e.g. view hierarchy construction. 5) If any code involved would call CES.openDocument() when under read/write lock there is a deadlock because CES will put this thread to sleep but as the thread still holds read/write lock on the doc the doc-loading RP cannot acquire the doc write lock and the loading will never proceed. In the attached dedlok the JavaParserGlue calls the CES.openDocument(). I was wondering whether it's necessary to assign the document to text component prior it gets fully loaded and I think it does not help much because even if the document gets assigned to the component the loading will write-lock it until it's fully loaded so the user will see the content _after_ the loading ends anyway (the repainting of the editor acquires read-lock so it will block until write-lock of loading RP gets released). I propose to change the current CloneableEditor.initialize() to call CES.openDocument() instead of CES.getDocumentHack(). Although by openDocument() we may block AWT for a while the user IMHO is waiting for the document to be opened and she would not do any useful work in the meantime anyway. I've prepared a patch that I have tested and there seem to be no problems with it. If you agree that this would be useful change please approve it or integrate it directly. Thanks.
Created attachment 13393 [details] Deadlock of AWT against document loading RP
Created attachment 13394 [details] Possible fix for the problem
I'd go even further and also simplify the code around (e.g. setting caret). I'll try it...
*** Issue 40047 has been marked as a duplicate of this issue. ***
Fixed (different patch). openide/src/org/openide/text/CloneableEditor.java,v1.69
*** Issue 40070 has been marked as a duplicate of this issue. ***
*** Issue 40073 has been marked as a duplicate of this issue. ***
*** Issue 40074 has been marked as a duplicate of this issue. ***
*** Issue 40072 has been marked as a duplicate of this issue. ***
*** Issue 40100 has been marked as a duplicate of this issue. ***
*** Issue 40148 has been marked as a duplicate of this issue. ***
I think it works fine now - verified
*** Issue 41503 has been marked as a duplicate of this issue. ***