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 180920 - Cannot "render" from inside undoableEditHappened
Summary: Cannot "render" from inside undoableEditHappened
Status: RESOLVED FIXED
Alias: None
Product: editor
Classification: Unclassified
Component: -- Other -- (show other bugs)
Version: 6.x
Hardware: Other Linux
: P3 normal (vote)
Assignee: Miloslav Metelka
URL:
Keywords:
: 184163 (view as bug list)
Depends on:
Blocks: 180614
  Show dependency tree
 
Reported: 2010-02-18 11:21 UTC by Jaroslav Tulach
Modified: 2010-04-14 14:58 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Unit test to demonstrate the problem (1.85 KB, patch)
2010-02-18 11:21 UTC, Jaroslav Tulach
Details | Diff
Patch for CESUndoRedoManager (6.11 KB, patch)
2010-03-10 02:54 UTC, Miloslav Metelka
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jaroslav Tulach 2010-02-18 11:21:03 UTC
Created attachment 94301 [details]
Unit test to demonstrate the problem

I am working on fix for bug 180614. However I have troubles to update state of Undo and Redo actions from inside undoableEditHappened listener event. The BaseDocument's locking mechanism gets confused somehow.

But I need to do it. I need to call UndoRedo.Manager (which acquires render lock on document) to find out whether canUndo and canRedo shall be enabled or not.

I am attaching simple test to demonstrate similar problem. The whole issue can be analyzed by applying patch provided for bug 180614.
Comment 1 Vitezslav Stejskal 2010-02-19 00:08:19 UTC
I don't think this is related to Printing & Painting...
Comment 2 Miloslav Metelka 2010-03-09 14:05:55 UTC
Yardo, if you would use
  doc.render(run);
inside undoableEditHappened() it would work as expected.
The
  doc.runAtomic(run)
does not work but it gives me a little meaning to use it inside undoableEditHappened() since you should not mutate the document there anyway. Is there any good reason why runAtomic() is necessary?
Comment 3 Jaroslav Tulach 2010-03-10 02:47:59 UTC
I can easily change the unit test, but the problem is that CloneableEditorSupport.getUndoRedo().canUndo() is using runAtomic. Who wants to change that? Imho, the runAtomic is there to prevent deadlocks.
Comment 4 Miloslav Metelka 2010-03-10 02:52:20 UTC
Yes, I know, I've already had a patch for CESUndoRedoManager's canUndo() and canRedo() with doc.render() and it seems to work fine so we could consider it.
Comment 5 Miloslav Metelka 2010-03-10 02:54:37 UTC
Created attachment 94961 [details]
Patch for CESUndoRedoManager
Comment 6 Miloslav Metelka 2010-03-10 02:57:07 UTC
BTW the partial code change in the patch for BaseDocument can stay it only clears the instance vars before firing the change. However it does not suffice for making your original test pass.
Comment 7 Miloslav Metelka 2010-03-17 12:56:53 UTC
The openide.text unit tests pass so I've committed the change.
http://hg.netbeans.org/jet-main/rev/41e2579c1947
Comment 8 Quality Engineering 2010-03-18 05:50:20 UTC
Integrated into 'main-golden', will be available in build *201003180200* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main/rev/41e2579c1947
User: Miloslav Metelka <mmetelka@netbeans.org>
Log: #180920 - Cannot "render" from inside undoableEditHappened - UndoRedo.canUndo()/canRedo() now use Document.render()
Comment 9 Jaroslav Tulach 2010-03-19 06:21:12 UTC
I am still getting NPE (with the bug 180614 patch) when typing a character in java editor:

java.lang.NullPointerException
	at org.netbeans.editor.BaseDocument.notifyModify(BaseDocument.java:1838)
	at org.netbeans.editor.BaseDocument.atomicUnlockImpl(BaseDocument.java:1801)
	at org.netbeans.editor.GuardedDocument.runAtomicAsUser(GuardedDocument.java:350)
	at org.netbeans.editor.BaseKit$DefaultKeyTypedAction.actionPerformed(BaseKit.java:1065)
	at org.netbeans.editor.ext.ExtKit$ExtDefaultKeyTypedAction.actionPerformed(ExtKit.java:1046)
	at org.netbeans.editor.BaseAction.actionPerformed(BaseAction.java:336)
	at javax.swing.SwingUtilities.notifyAction(SwingUtilities.java:1636)
	at javax.swing.JComponent.processKeyBinding(JComponent.java:2851)
	at javax.swing.JComponent.processKeyBindings(JComponent.java:2886)
	at javax.swing.JComponent.processKeyEvent(JComponent.java:2814)
	at java.awt.Component.processEvent(Component.java:6040)
Comment 10 Vitezslav Stejskal 2010-03-22 15:01:15 UTC
I think this should solve the NPE.
http://hg.netbeans.org/jet-main/rev/9f5cece14acf
Comment 11 Quality Engineering 2010-03-24 05:18:32 UTC
Integrated into 'main-golden', will be available in build *201003240200* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main/rev/9f5cece14acf
User: Vita Stejskal <vstejskal@netbeans.org>
Log: #180920: following up on 41e2579c1947, there are more readonly operations
Comment 12 Vitezslav Stejskal 2010-04-14 14:58:36 UTC
*** Bug 184163 has been marked as a duplicate of this bug. ***