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 42005 - CloneableEditorSupportTest: testDocumentCannotBeModified
Summary: CloneableEditorSupportTest: testDocumentCannotBeModified
Status: CLOSED WORKSFORME
Alias: None
Product: platform
Classification: Unclassified
Component: Text (show other bugs)
Version: 4.x
Hardware: PC Linux
: P2 blocker (vote)
Assignee: Jaroslav Tulach
URL:
Keywords: TEST
: 38112 46411 (view as bug list)
Depends on:
Blocks:
 
Reported: 2004-04-15 08:07 UTC by Jaroslav Tulach
Modified: 2008-12-22 20:37 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
The failure (6.40 KB, text/html)
2004-04-15 08:07 UTC, Jaroslav Tulach
Details
Making UndoRedo.Manager synchronous (11.08 KB, patch)
2004-07-26 13:09 UTC, Jaroslav Tulach
Details | Diff
exception stacktrace (1.37 KB, text/plain)
2004-08-23 13:05 UTC, pzajac
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jaroslav Tulach 2004-04-15 08:07:22 UTC
This is probably cause by asynch impl of UndoRedo
manager. We should make it synchronous at least
from AWT thread!?

testDocumentCannotBeModified	fail	For a while the
test really starts with Kuk expected:<Kuk> but
was:<Aho>
Comment 1 Jaroslav Tulach 2004-04-15 08:07:49 UTC
Created attachment 14407 [details]
The failure
Comment 2 Jaroslav Tulach 2004-07-26 13:09:22 UTC
The problem is caused by the asynchronous communication between
UndoRedo.Manager and CloneableEditorSupport. The asynchronous code has
been introduced due to bug 8692, which I believe has been made
obsolete by the sharing of AbstractDocument.lock() for most of the
document operations. That is why I investigated a removal of the
asynchronous code. It seems that the deadlock is not there anymore and
moreover the code becomes more reliable. I'll attach my patch and wait
for Petr's and Mila's review.
Comment 3 Jaroslav Tulach 2004-07-26 13:09:58 UTC
Created attachment 16443 [details]
Making UndoRedo.Manager synchronous
Comment 4 Jaroslav Tulach 2004-07-27 11:02:37 UTC
I am about to commit this change and make UndoRedo.Manager synchronous
again.
Comment 5 Jaroslav Tulach 2004-07-27 12:22:05 UTC
Checking in src/org/openide/awt/UndoRedo.java;
/cvs/openide/src/org/openide/awt/UndoRedo.java,v  <--  UndoRedo.java
new revision: 1.25; previous revision: 1.24
done
Processing log script arguments...
More commits to come...
Checking in src/org/openide/text/CloneableEditorSupport.java;
/cvs/openide/src/org/openide/text/CloneableEditorSupport.java,v  <-- 
CloneableEditorSupport.java
new revision: 1.125; previous revision: 1.124
done
Processing log script arguments...
More commits to come...
Checking in
test/unit/src/org/openide/text/CloneableEditorSupportTest.java;
/cvs/openide/test/unit/src/org/openide/text/CloneableEditorSupportTest.java,v
 <--  CloneableEditorSupportTest.java
new revision: 1.6; previous revision: 1.5
done
RCS file:
/cvs/openide/test/unit/src/org/openide/text/UndoRedoCooperationTest.java,v
done
Checking in test/unit/src/org/openide/text/UndoRedoCooperationTest.java;
/cvs/openide/test/unit/src/org/openide/text/UndoRedoCooperationTest.java,v
 <--  UndoRedoCooperationTest.java
initial revision: 1.1
Comment 6 Miloslav Metelka 2004-07-27 14:58:29 UTC
I have looked again to Swing document implementations and UndoManager
and I have found a particular limitation for certain circumstances.
As there are two locks - one is the UndoManager and the other one is
the document's lock we need to avoid counterlocking. That may occur when
Thread-1: 1. Document modification insert/remove
          2. Firing undo listeners under document's lock incl. UndoManager
          3. UndoManager.addEdit() -> UM's lock

Thread-2: 1. UndoManager.undo() -> UM's lock
          2. AbstractDocument.DefaultDocumentEvent.undo() -> doc's lock

So to avoid the counterlocking we need to make both the threads above
to be just a single thread - likely the AWT thread. As Jesse indicated
earlier during his work on the IDE's thread model he would like to
have all the document modifications/operations to be performed in AWT.
I guess the UM's operations are done in AWT naturally as they are
invoked by shortcuts/toolbar-icons. However I guess the current policy
does not require both doc and UM to be run in AWT does it?
Comment 7 Jaroslav Tulach 2004-07-27 16:18:03 UTC
Nothing in UndoRedo.Manager is final, so we might completely
reimplement it by ourselves if needed and force it to use Document's
lock, I guess.

However as stated at 
http://www.netbeans.org/download/dev/javadoc/OpenAPIs/org/openide/doc-files/threading.html
WindowsAPI (including top component and getUndoRedo()) is supposed to
be called just from AWT.

However I am going to try to simulate your described deadlock and
check whether there is something to do about it (I expect overriding
undo and getting lock first before calling super might be enough).
Comment 8 Jaroslav Tulach 2004-07-28 13:35:04 UTC
cvs -q ci -m "#42005: Simulating and preventing the deadlock described
by mmetelka@netbens.org in his comment in issue 42005"
Checking in src/org/openide/text/CloneableEditorSupport.java;
/cvs/openide/src/org/openide/text/CloneableEditorSupport.java,v  <-- 
CloneableEditorSupport.java
new revision: 1.126; previous revision: 1.125
done
Processing log script arguments...
More commits to come...
RCS file:
/cvs/openide/test/unit/src/org/openide/text/NbLikeEditorKit.java,v
done
Checking in test/unit/src/org/openide/text/NbLikeEditorKit.java;
/cvs/openide/test/unit/src/org/openide/text/NbLikeEditorKit.java,v 
<--  NbLikeEditorKit.java
initial revision: 1.1
done
Checking in test/unit/src/org/openide/text/UndoRedoCooperationTest.java;
/cvs/openide/test/unit/src/org/openide/text/UndoRedoCooperationTest.java,v
 <--  UndoRedoCooperationTest.java
new revision: 1.2;
Comment 9 Miloslav Metelka 2004-07-28 15:01:55 UTC
Regarding the case when the document impl is not instance of
NbDocument.WriteLockable (e.g. when being run without the editor
module being turned on) I think that we cannot use doc.render()
because this would require promotion of document read lock to write
lock which is not allowed:
 1) doc.render() acquires document read lock
 2) UM.undo() acquires UM lock
 3) AbstractDocument.DefaultDocumentEvent.undo() calls writeLock()
which should cause the thread to sleep and never wake up.
Comment 10 Jaroslav Tulach 2004-07-28 16:10:11 UTC
Thank you Mila, I've forget the render there from my previous
experiments. Just run is better, even not perfect:
 
cvs ci -m "#42005: Yet another change - cannot upgrade readlock to
writelock on AbstractDocument. That is why we can do no tricks on
non-NbDocument.WriteLockable documents. Maybe reflection. But until
real fix is needed, we can just use no locks."



/cvs/openide/src/org/openide/text/CloneableEditorSupport.java,v  <-- 
CloneableEditorSupport.java
new revision: 1.127; previous revision: 1.126
done
Processing log script arguments...
More commits to come...
Checking in test/unit/src/org/openide/text/UndoRedoCooperationTest.java;
/cvs/openide/test/unit/src/org/openide/text/UndoRedoCooperationTest.java,v
 <--  UndoRedoCooperationTest.java
new revision: 1.3; previous revision: 1.2
Comment 11 Jaroslav Tulach 2004-08-03 09:56:25 UTC
*** Issue 46411 has been marked as a duplicate of this issue. ***
Comment 12 Petr Nejedly 2004-08-16 15:56:15 UTC
*** Issue 38112 has been marked as a duplicate of this issue. ***
Comment 13 pzajac 2004-08-23 13:04:31 UTC
The test failed on :
200408221800 
Host	:	qa-frodo
Operating System Name	:	SunOS
Operating System Version	:	5.9
System Architecture	:	sparc
Java Version	:	1.4.2_05
Java Vendor	:	Sun Microsystems Inc.
User Language	:	en
Comment 14 pzajac 2004-08-23 13:05:26 UTC
Created attachment 17025 [details]
exception stacktrace
Comment 15 Jaroslav Tulach 2004-08-24 16:40:04 UTC
I hope that this is fixed as well as the other issues related to undo
redo in CES.
Comment 16 Jaromir Uhrik 2005-07-14 16:20:25 UTC
Verified.