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 56963 - [data loss] undo does not mark file as dirty
Summary: [data loss] undo does not mark file as dirty
Status: CLOSED FIXED
Alias: None
Product: editor
Classification: Unclassified
Component: -- Other -- (show other bugs)
Version: 4.x
Hardware: All All
: P1 blocker (vote)
Assignee: Miloslav Metelka
URL:
Keywords:
: 57054 57075 (view as bug list)
Depends on:
Blocks: 57302
  Show dependency tree
 
Reported: 2005-03-25 02:01 UTC by athompson
Modified: 2007-11-05 13:44 UTC (History)
3 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Possible fix for the editor - still needs some additional fix on openide/editor side (7.93 KB, patch)
2005-03-29 16:22 UTC, Miloslav Metelka
Details | Diff
Test that works without any changes in openide (2.98 KB, patch)
2005-04-04 03:47 UTC, Jaroslav Tulach
Details | Diff
Openide tests diff (3.18 KB, patch)
2005-04-04 14:36 UTC, Miloslav Metelka
Details | Diff
Editor fix (4.07 KB, patch)
2005-04-04 14:36 UTC, Miloslav Metelka
Details | Diff
Deadlock during added redo in the test (5.88 KB, text/plain)
2005-04-04 14:38 UTC, Miloslav Metelka
Details
Fulldiff with yet another test for reload - all tests are now passing fine (12.94 KB, patch)
2005-04-04 15:03 UTC, Jaroslav Tulach
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description athompson 2005-03-25 02:01:25 UTC
jdk-1.5
linux
daily 20040323

1. open a java file (i haven't checked other types)
2. modify the file. the dirty flag (asterisk on tab) shows up. this is ok.
3. save file. dirty flag goes away. this is ok.
4! press undo (ctrl-z). changes are undone but file is not marked as modified.

this is a P1 because someone may unwittingly exit without saving (since the IDE
doesn't think the file is dirty, it won't prompt to save changes). in fact, the
IDE will actually PREVENT you from saving since the dirty flag is not set.

it's impossible to tell if redo has the same problem until undo is fixed.
Comment 1 Roman Strobl 2005-03-25 08:12:14 UTC
I was able to reproduce the bug. It can lead to dataloss, indeed. Please fix ASAP.
Comment 2 Miloslav Metelka 2005-03-25 08:54:52 UTC
Looks like the issue 56834 describes the similar if not the same problem. I'll
leave both of them open for now.
Comment 3 Miloslav Metelka 2005-03-25 12:14:59 UTC
Well, I probably know what's wrong. Due to the fix of issue 51872 it's now
necessary to do some special treatment of the edits which is probably not done
appropriately during undo. I'll investigate more.
Comment 4 Miloslav Metelka 2005-03-25 13:35:45 UTC
BTW I've tested daily build 20050314 (prior issue 51872 integration) and it
works fine. 51872 was integrated on 2005/03/16.
This issue can be reproduced since build 20050317 so it's likely caused by 51872
integration.
Comment 5 Miloslav Metelka 2005-03-29 09:55:03 UTC
*** Issue 57075 has been marked as a duplicate of this issue. ***
Comment 6 Miloslav Metelka 2005-03-29 11:41:02 UTC
Well, it's clear why it fails. The DocumentEvent.undo() just does undo of its
contained edits and fires document listener. Since the notifyModified() no
longer watches the DocumentListener but instead has its own treatment it will
ignore the firing of the listener and the document will remain unmodified.
I'll try to fix on my side. We should certainly add a test for this case on
openide/editor side as well.
Comment 7 Miloslav Metelka 2005-03-29 16:22:03 UTC
Created attachment 21200 [details]
Possible fix for the editor - still needs some additional fix on openide/editor side
Comment 8 Miloslav Metelka 2005-03-29 16:27:38 UTC
I've made the possible fix for the editor but it seems that it still needs some
additional fixing on openide/editor side. I have been trying to debug the
processing in CloneableEditorSupport but it's rather complicated due to all the
present fixes including the one for issue 51872. Yarda's help would be much
appreciated.
Comment 9 Martin Roskanin 2005-03-30 11:07:00 UTC
*** Issue 57054 has been marked as a duplicate of this issue. ***
Comment 10 Martin Roskanin 2005-03-30 11:09:55 UTC
*** Issue 57054 has been marked as a duplicate of this issue. ***
Comment 11 Miloslav Metelka 2005-03-30 12:54:49 UTC
I've done additional change on editor side that seems to fix the problem
completely. After testing I'll commit it.
Comment 12 Miloslav Metelka 2005-03-30 13:59:59 UTC
Fixed in main trunk:
Checking in libsrc/org/netbeans/editor/BaseDocument.java;
/cvs/editor/libsrc/org/netbeans/editor/BaseDocument.java,v  <--  BaseDocument.java
new revision: 1.118; previous revision: 1.117
done
Checking in libsrc/org/netbeans/editor/BaseDocumentEvent.java;
/cvs/editor/libsrc/org/netbeans/editor/BaseDocumentEvent.java,v  <-- 
BaseDocumentEvent.java
new revision: 1.21; previous revision: 1.20
Comment 13 Roman Strobl 2005-04-01 13:42:16 UTC
The following case fails:

1. Open any file in editor.
2. Select all contents.
3. Press delete.
4. Save file.
5. Undo changes.

After step 5 you are not able to save the file. Thus you may loose the whole
content of the file if you loose your clipboard.

It works fine in 4.0 so it is a regression.
Comment 14 Miloslav Metelka 2005-04-01 14:26:41 UTC
I'll investigate.
Comment 15 Jaroslav Tulach 2005-04-03 19:16:26 UTC
Let's try to write a test tomorrow.
Comment 16 Jaroslav Tulach 2005-04-04 03:47:31 UTC
Created attachment 21325 [details]
Test that works without any changes in openide
Comment 17 Jaroslav Tulach 2005-04-04 03:54:46 UTC
I've just attached test for the broken behaviour. It works correctly with plain
NotifyModifiedTest and after small change in NbLikeEditorKit also with
NotifyModifiedOnNbEditorLikeKitTest.

The problem is that when doing undo on AbstractDocument the StringContent
changes without calling AbstractDocument.insertString or
AbstractDocument.remove. I had to override fire*** methods to be notified of
such changes.

Right now my version (a week outdated) of InheritedNotifyModifiedTest fails, but
I guess that similiar fix as I used in NbLikeEditorKit can be used in editor as
well. Please try it and if it works please integrate my test at least to trunk
together with your fix.
Comment 18 Miloslav Metelka 2005-04-04 14:32:50 UTC
Yardo, I've already did the same sort of changes in the editor module in
BaseDocument and BaseDocumentEvent. Maybe my ones are slightly more elaborated
;) because if I understand your changes correctly you just increment the changes
variable in fire* methods and rely that the undo/redo changes are invoked under
runAtomic() which then fires the modificationListener (which is true thanks to
the  fact that CESUndoRedoManager wraps each operation with RenderUndo). My
undo/redo impl would work even without being wrapped runAtomic(). But that's
just a nitpick.

I've found what's the problem with the first undo - the inUndoRedo flag passed
to BaseDocument.atomicUnlockImpl() was incorrectly set to false for the first
undo so I've fixed that by using another way of marking that there were any
edits undone or redone. Your extra test then passes with the BaseDocument
implementation but then I've found that once I do redo the document content is
deleted properly but the file stays modified which is an error. So I've added
the redo() test into your extra test but then the test deadlocks every time (at
least on my machine). I'm attaching my BaseDocument changes and the modified
openide test and the deadlock dump.
Comment 19 Miloslav Metelka 2005-04-04 14:36:03 UTC
Created attachment 21346 [details]
Openide tests diff
Comment 20 Miloslav Metelka 2005-04-04 14:36:56 UTC
Created attachment 21347 [details]
Editor fix
Comment 21 Miloslav Metelka 2005-04-04 14:38:04 UTC
Created attachment 21348 [details]
Deadlock during added redo in the test
Comment 22 Jaroslav Tulach 2005-04-04 15:03:48 UTC
Created attachment 21350 [details]
Fulldiff with yet another test for reload - all tests are now passing fine
Comment 23 Miloslav Metelka 2005-04-04 15:45:25 UTC
Yardo, one more thing that fails:
1) file open
2) any modification
3) undo
4) file is still marked dirty

Test method (now it deadlocks in a similar way like the previous one):

    public void testUndoMarksFileUnmodified () throws Exception {
        content = "Somecontent";
        
        final javax.swing.text.StyledDocument doc = support.openDocument();

        int len = doc.getLength ();
        
        assertEquals ("Content opened", "Somecontent", doc.getText (0, len));
        
        doc.remove (0, len);
        
        assertTrue ("Document is modified", support.isModified ());
        assertTrue ("Can undo", support.getUndoRedo ().canUndo ());
        
        support.getUndoRedo ().undo ();
        
        assertTrue ("Document is unmodified", !support.isModified ());    
    }
    
Comment 24 Jaroslav Tulach 2005-04-04 18:04:46 UTC
"#56963: Four new ways how to break yesterday's undo/redo support in
CloneableEditorSupport automated and fixed. Works fine for all nb-like editor
kits, however has intermitent problems with non-nb-like ones. But as the fix for
nb-lie ones is more important I am integrating to trunk anyway to reach wider
audience and get feed back. Either confirmation that it works or new ways to
still break the support"


Checking in openide/src/org/openide/text/CloneableEditorSupport.java;
/cvs/openide/src/org/openide/text/CloneableEditorSupport.java,v  <-- 
CloneableEditorSupport.java
new revision: 1.151; previous revision: 1.150
done
Checking in openide/test/unit/src/org/openide/text/NbLikeEditorKit.java;
/cvs/openide/test/unit/src/org/openide/text/NbLikeEditorKit.java,v  <-- 
NbLikeEditorKit.java
new revision: 1.5; previous revision: 1.4
done
Checking in openide/test/unit/src/org/openide/text/NotifyModifiedTest.java;
/cvs/openide/test/unit/src/org/openide/text/NotifyModifiedTest.java,v  <-- 
NotifyModifiedTest.java
new revision: 1.7; previous revision: 1.6
done
Checking in editor/libsrc/org/netbeans/editor/BaseDocument.java;
/cvs/editor/libsrc/org/netbeans/editor/BaseDocument.java,v  <--  BaseDocument.java
new revision: 1.120; previous revision: 1.119
done
Checking in editor/libsrc/org/netbeans/editor/BaseDocumentEvent.java;
/cvs/editor/libsrc/org/netbeans/editor/BaseDocumentEvent.java,v  <-- 
BaseDocumentEvent.java
new revision: 1.23; previous revision: 1.22
Comment 25 Milan Kubec 2005-04-06 09:33:30 UTC
Shouldn't this be marked with 41_HR_FIX kw?
Comment 26 Miloslav Metelka 2005-04-06 09:54:41 UTC
Yes, I've added the keyword.
I would like to ask Petr N. to check and approve the fix. For me the fix looks fine.
Comment 27 Petr Nejedly 2005-04-07 14:47:20 UTC
The changes in CloneableEditorSupport.java look sane and complete to me.
I won't pretend I deeply understand BaseDocument impl but the changes look OK to
me. Any more reviewer able to check BaseDocument deeper?
Comment 29 Martin Roskanin 2005-04-07 17:08:31 UTC
Yes, the changes in BaseDocument and BaseDocumentEvent seem fine to me. The
logic of the change is clear. 
(But as for the global mechanism of locking, notifying and firing - Mila, Jarda,
it's up to you :-) ) 
Comment 30 Roman Strobl 2005-04-07 18:17:01 UTC
I've tested the issue on build 200504061800, it works well here. Didn't see any
case where the dirty mark would be missing. Please procceed with integration
into 4.1 branch. Thanks.
Comment 31 Jaroslav Tulach 2005-04-08 16:15:27 UTC
"#57104,#56963: Backport of undo/redo/save fixes in editor" 
Checking in openide/src/org/openide/text/CloneableEditorSupport.java; 
/cvs/openide/src/org/openide/text/CloneableEditorSupport.java,v  <--  
CloneableEditorSupport.java 
new revision: 1.150.2.1; previous revision: 1.150 
done 
Checking in openide/test/unit/src/org/openide/text/NbLikeEditorKit.java; 
/cvs/openide/test/unit/src/org/openide/text/NbLikeEditorKit.java,v  <--  
NbLikeEditorKit.java 
new revision: 1.4.4.1; previous revision: 1.4 
done 
Checking in openide/test/unit/src/org/openide/text/NotifyModifiedTest.java; 
/cvs/openide/test/unit/src/org/openide/text/NotifyModifiedTest.java,v  <--  
NotifyModifiedTest.java 
new revision: 1.6.4.1; previous revision: 1.6 
done 
Checking in editor/libsrc/org/netbeans/editor/BaseDocument.java; 
/cvs/editor/libsrc/org/netbeans/editor/BaseDocument.java,v  <--  
BaseDocument.java 
new revision: 1.119.2.1; previous revision: 1.119 
done 
Checking in editor/libsrc/org/netbeans/editor/BaseDocumentEvent.java; 
/cvs/editor/libsrc/org/netbeans/editor/BaseDocumentEvent.java,v  <--  
BaseDocumentEvent.java 
new revision: 1.21.2.1; previous revision: 1.21 
Comment 32 Roman Strobl 2005-04-13 10:03:52 UTC
Setting TM to 4.1 as the fix was backported to 4.1 branch. See:
http://www.netbeans.org/community/releases/41/high-resistance.html
Comment 33 Roman Strobl 2005-07-14 14:00:21 UTC
Verified in 200507131800.