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 218626 - Editor is not writing to file
Summary: Editor is not writing to file
Status: RESOLVED FIXED
Alias: None
Product: editor
Classification: Unclassified
Component: Actions/Menu/Toolbar (show other bugs)
Version: 7.2
Hardware: All All
: P1 normal with 1 vote (vote)
Assignee: Miloslav Metelka
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-09-19 14:54 UTC by moein
Modified: 2012-10-03 09:50 UTC (History)
7 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Log (552.19 KB, application/octet-stream)
2012-09-21 08:17 UTC, moein
Details
Log #2 (585.88 KB, application/octet-stream)
2012-09-21 12:47 UTC, moein
Details
Deadlock of the test (9.31 KB, text/plain)
2012-10-03 08:58 UTC, Miloslav Metelka
Details

Note You need to log in before you can comment on or make changes to this bug.
Description moein 2012-09-19 14:54:47 UTC
Netbeans 7.2 seems to have the same bug mentioned in Bug 206513
My friend to experienced it once(using windows 7) but for me it's like 5 or 6 times a week
It wasn't really annoying but recently I lost lots of code I wrote since Netbeans was telling me that it had saved the file but when I closed it and then returned to change something all of my changes were lost
Comment 1 Miloslav Metelka 2012-09-20 06:49:25 UTC
Was there a problem with a disabled Save action or it seemed to be saving the file but the changes were not written to the disk? Any other info that could help us to reproduce the problem?
Could you attach your messages.log file? Thanks.
Comment 2 moein 2012-09-20 11:00:23 UTC
It seemed that file is saved but changes weren't written to the disk that's why I thought that everything is okay and I lost my code
Sorry for log I have weekly cron to clean the messages and it was exactly last night -.-
I will attach the log as soon as I see the same behavior
Comment 3 moein 2012-09-20 14:28:38 UTC
So it happened again
I was editing a file
*I saved it(Netbeans show me it's saved)
I went to console and executed a command that reads the file(until here the changes were written to the disk)
I fixed the error and again saved it(Netbeans showed it's saved)
But now when I go to the file with emacs or using cat to see the content it's the old same content from when I saved the file for the first time(in *)
I thought by messages.log you mean my system message log but I found out that Netbeans has a separate message file
But in /Users/moein/.netbeans directory I only can see a single directory which is 7.1.1 which is the older version that I had installed
So what should I do now?
Comment 4 Miloslav Metelka 2012-09-20 20:07:34 UTC
It should be described in http://wiki.netbeans.org/FaqLogMessagesFile
Comment 5 Miloslav Metelka 2012-09-21 08:07:14 UTC
What type is the file? Is the file versioned? (adding Tomas S. to cc to possibly help us if it would be VCS related).
moein please provide the log there could be a key information to help us to resolve the problem.
Comment 6 moein 2012-09-21 08:17:36 UTC
Created attachment 124684 [details]
Log

Miloslav Metelka Thanks for the tip I found the log file
The file is versioned by git but a little look at log seems to show the bug
I normally copy a file in the folder and then change it's name
From what log shows it seems netbeans stick with the old name and just throw the exception of file not found
java.io.FileNotFoundException: /Users/moein_ak/Projects/...../DataFixtures/ORM/LoadFamilyData_1.php
LoadFamilyData_1 is the copy of LoadFamilyData that after that I changed it's name to something else
I hope it helps to fix the bug
Comment 7 Miloslav Metelka 2012-09-21 10:32:05 UTC
Thanks for the log.
When you copied and renamed the file you do it in NB or from command line? You did it before the first save (marked with * in comment 3)?
 As you mentioned there are exceptions from a localhistory module that it cannot find the given file. One hint given to me by tstupka was to attempt to test the IDE with localhistory module disabled so we could possibly try that then.
Comment 8 moein 2012-09-21 10:35:40 UTC
@Miloslav Metelka
I normally do the following
I copy the file
Change the name
Open the file and edit it
I will try to look more carefully what I do to tell you exactly when it happens(It's funny that when I try to reproduce the error I can't and when I don't want to it will be reproduced :D)
Comment 9 moein 2012-09-21 10:37:02 UTC
By the way I'm using netbeans to copy the file
Comment 10 moein 2012-09-21 10:40:45 UTC
Sorry for continuous comments but this might help you
Sometimes that I find out that the file is not being saved I do the following(it seems using touch force netbeans to reload the file)
The case:
I have a file Test.php
I copy and paste -> new file Test_1.php
I rename it to NewTest.php(with netbeans)
I start making changes to NewTest.php
I save it(Netbeans shows me that the file is saved)
I execute the file but from the error I get it's clear it's still with the content of Test.php
I execute touch NewTest.php and Netbeans reload the old content(content of Test.php) into the editor
Hope it helps
Comment 11 moein 2012-09-21 12:47:31 UTC
Created attachment 124707 [details]
Log #2

It happened again
But this time I didn't copy anything
I simply created a new php file(with netbeans)
I started editing
After 2 or 3 lines I saved the file
I surfed on the web for 5-10 minutes then came back to finish the code
After I finished I saved the file again but then I noticed again the changes aren't being written to the disk(using emacs I can see it's the content of the first time I saved)
I attach again my log
Comment 12 Vladimir Voskresensky 2012-09-24 12:30:44 UTC
The same issue on Solaris
Comment 13 Tomas Danek 2012-09-24 13:46:35 UTC
I was not able to reproduce using scenario from comment #10:
- created php project (left everything default)
( created/Applications/MAMP/htdocs/PhpProject4)
- copy on index.php
- paste created index_1.php
- renamed index_1.php -> renamed.php
- opened renamed.php
- editing, saving, switching to browser and  back, editing again, saving.... everything works as expected.

Product Version: NetBeans IDE 7.2 (Build 201207171143)
Java: 1.7.0_10-ea; Java HotSpot(TM) 64-Bit Server VM 23.6-b02
System: Mac OS X version 10.8.2 running on x86_64; US-ASCII; en_US (nb)
User directory: /Users/tomas/Library/Application Support/NetBeans/7.2
Cache directory: /Users/tomas/Library/Caches/NetBeans/7.2
Comment 14 moein 2012-09-24 13:50:44 UTC
The problem about the bus is that it's not reproduced every time I copy a file
It's totally random and unexpected
Comment 15 Miloslav Metelka 2012-09-24 14:29:28 UTC
Could you check whether disabling "Local History" module affects the problem or not? To disable LH:
1) Goto Tools->Plugins->Installed.
2) Click "Show details".
3) Search for "local".
4) Select the module
5) Click "Deactivate" button.
Comment 16 Miloslav Metelka 2012-09-24 14:33:43 UTC
Could you run the IDE with

-J-Dorg.openide.text.CloneableEditorSupport.level=FINE

(possibly check http://wiki.netbeans.org/FaqNetbeansConf)
Thanks.
Comment 17 moein 2012-09-24 14:44:09 UTC
Hmm I will try it but that doesn't sound good to me because local history is one of the things that I really love about netbeans and I use it constantly
Comment 18 Miloslav Metelka 2012-09-24 15:57:06 UTC
Sure, we just need to sort out where the problem is and since Tomas Stupka said that the exception from localhistory in the log should not be fatal we should resolve whether the problem is related to something in the localhistory or the rest of the IDE.
Comment 19 Tomas Stupka 2012-09-24 16:07:37 UTC
(In reply to comment #17)
> Hmm I will try it but that doesn't sound good to me because local history is
> one of the things that I really love about netbeans and I use it constantly
we struggle to reproduce the problem, so maybe you could try your scenario a couple of times with LH disabled. In case you can confirm that the problem happens to you also with LH disabled it would help us to narrow down the scope of where the bug could possible come from. 

are those files local or from a remote mount? are there any symlinks involved? also anything else related to your file setup could be of use ...

thanks
Comment 20 moein 2012-09-24 16:22:42 UTC
(In reply to comment #19)
> (In reply to comment #17)
> > Hmm I will try it but that doesn't sound good to me because local history is
> > one of the things that I really love about netbeans and I use it constantly
> we struggle to reproduce the problem, so maybe you could try your scenario a
> couple of times with LH disabled. In case you can confirm that the problem
> happens to you also with LH disabled it would help us to narrow down the scope
> of where the bug could possible come from. 
> 
> are those files local or from a remote mount? are there any symlinks involved?
> also anything else related to your file setup could be of use ...
> 
> thanks

Ok
Give a week to try doing the same things with LH disabled and I will tell you the result on Friday
Regarding your questions
All the files are local
There is no symlink involved at least not in the part i'm editing
And there isn't any special configuration for hard disk on my machine
I have the problem like daily so it will be easy to see if it's because of LH or not
Thanks for the support
Comment 21 moein 2012-09-24 16:45:34 UTC
Hi guys
I just deactivated LH and added the parameter Miloslav Metelka that gave me to the configuration file using the documentation
Disabling the LH plugin caused lots of plugins to be disabled
After I started netbeans again now the problem is when I open a file and edit it and try to save it I can't
The only way to save it is to close the file and save it when netbeans prompt to what to do  (Discard, Cancel, Save changes)
I really can't try if the problem is from LH or not if netbeans is working like this
Comment 22 Tomas Stupka 2012-09-24 22:40:18 UTC
(In reply to comment #21)
> Disabling the LH plugin caused lots of plugins to be disabled
strange. i was able to deactivate LH in 7.2 as well as in a dev build without any side effects. 
please, don't get me wrong, but are you sure you selected only the LH plugin in the plugin manager?
Comment 23 moein 2012-09-24 23:09:27 UTC
Ok I was able to disable local history without any side effect
Don't know why the first time netbeans told me that all those modules had dependency on LH
I will try to reproduce the error with LH disabled
Comment 24 Vladimir Voskresensky 2012-09-25 09:10:12 UTC
Andrew, can you help to reproduce this issue with more logging as well (run IDE as asked in comments 15&16)
Comment 25 Miloslav Metelka 2012-09-25 09:48:42 UTC
(In reply to comment #23)
> Ok I was able to disable local history without any side effect
> Don't know why the first time netbeans told me that all those modules had
> dependency on LH
> I will try to reproduce the error with LH disabled

Thanks. Please note that turning on any logging (e.g. the one from comment 16) may affect the race condition problems like this. Therefore if you run both with LH disabled and the logging then (if the problem would not occur) please turn off the logging and double check that the problem still does not occur. Thanks.
Comment 26 Andrew Krasny 2012-09-25 16:32:18 UTC
Hi, 

I'm currently running a NB that is in this situation... 
(Sorry, I'm not using mentioned flags, but I can attach to it with a debugger)
From a debug session I see that:

Then I type in a document, a CloneableEditorSupport.callNotifyModified() is called. But isAlreadyModified() is set to true, so notifyModified() is not called.

From the other side, cesEnv().isModified() returns false => file is not saved on Save action...

So when I set a breakpoint in isAlreadyModified() method, I see:
alreadyModified - true
cesEnv().isModified() - false

Does it give you any clue? (If you want to debug this session - give me a call)

=Andrew
Comment 27 Andrew Krasny 2012-09-25 17:08:10 UTC
One additional note... 
alreadyModified flag in CES is not synchronized nor volatile.. and accessed from different threads simultaneously... 
Most likely this is the reason of the race...
Comment 28 Andrew Krasny 2012-09-27 16:19:11 UTC
Below are reproducible (in debugger) steps:

- Set breakpoint at CloneableEditorSupport.setAlreadyModified:2656
  2656 this.alreadyModified = alreadyModified;

- open a file;
=> bp hit in non-awt thread (param alreadyModified == false) [stack1]

- type smth in editor (it is not blocked)
=>bp hit in EDT (param alreadyModified == true) [stack2]

depending on timing this.alreadyModified is either true or false

[stack1]:
"Inactive RequestProcessor thread [Was:CsmDecisionFileTaskFactory/org.netbeans.modules.cnd.model.tasks.CsmFileTaskFactory$3]"
org.openide.text.CloneableEditorSupport.setAlreadyModified(CloneableEditorSupport.java:2656)
org.openide.text.CloneableEditorSupport.callNotifyUnmodified(CloneableEditorSupport.java:1981)
org.openide.text.CloneableEditorSupport.doCloseDocument(CloneableEditorSupport.java:2240)
org.openide.text.CloneableEditorSupport.access$1800(CloneableEditorSupport.java:129)
org.openide.text.CloneableEditorSupport$9.run(CloneableEditorSupport.java:2213)
org.netbeans.editor.BaseDocument.render(BaseDocument.java:1353)
org.openide.text.CloneableEditorSupport.closeDocument(CloneableEditorSupport.java:2197)
org.openide.text.CloneableEditorSupport.notifyClosed(CloneableEditorSupport.java:2065)
org.openide.text.DataEditorSupport.notifyClosed(DataEditorSupport.java:422)
org.openide.text.CloneableEditorSupport.close(CloneableEditorSupport.java:2167)
org.openide.windows.CloneableOpenSupport.close(CloneableOpenSupport.java:129)
org.netbeans.modules.versioning.ui.diff.DiffSidebar.getText(DiffSidebar.java:1062)
org.netbeans.modules.versioning.ui.diff.DiffSidebar.getText(DiffSidebar.java:965)
org.netbeans.modules.versioning.ui.diff.DiffSidebar.access$1500(DiffSidebar.java:114)
org.netbeans.modules.versioning.ui.diff.DiffSidebar$RefreshDiffTask.fetchOriginalContent(DiffSidebar.java:923)
org.netbeans.modules.versioning.ui.diff.DiffSidebar$RefreshDiffTask.computeDiff(DiffSidebar.java:892)
org.netbeans.modules.versioning.ui.diff.DiffSidebar$RefreshDiffTask.run(DiffSidebar.java:877)
org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:1454)
org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:2036)

[stack2]:
"AWT-EventQueue-1"
org.openide.text.CloneableEditorSupport.setAlreadyModified(CloneableEditorSupport.java:2656)
org.openide.text.CloneableEditorSupport.callNotifyModified(CloneableEditorSupport.java:1969)
org.openide.text.CloneableEditorSupport$Listener.vetoableChange(CloneableEditorSupport.java:2867)
org.netbeans.editor.BaseDocument.atomicLockImpl(BaseDocument.java:1676)
org.netbeans.editor.GuardedDocument.runAtomicAsUser(GuardedDocument.java:343)
org.netbeans.editor.BaseKit$DefaultKeyTypedAction.actionPerformed(BaseKit.java:1167)
org.netbeans.editor.ext.ExtKit$ExtDefaultKeyTypedAction.actionPerformed(ExtKit.java:1081)
org.netbeans.editor.BaseAction.actionPerformed(BaseAction.java:339)
javax.swing.SwingUtilities.notifyAction(SwingUtilities.java:1633)
javax.swing.JComponent.processKeyBinding(JComponent.java:2851)
javax.swing.JComponent.processKeyBindings(JComponent.java:2886)
javax.swing.JComponent.processKeyEvent(JComponent.java:2814)
java.awt.Component.processEvent(Component.java:6040)
java.awt.Container.processEvent(Container.java:2041)
java.awt.Component.dispatchEventImpl(Component.java:4630)
java.awt.Container.dispatchEventImpl(Container.java:2099)
java.awt.Component.dispatchEvent(Component.java:4460)
java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1850)
java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.java:712)
java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:990)
java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:855)
java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:676)
java.awt.Component.dispatchEventImpl(Component.java:4502)
java.awt.Container.dispatchEventImpl(Container.java:2099)
java.awt.Window.dispatchEventImpl(Window.java:2478)
java.awt.Component.dispatchEvent(Component.java:4460)
java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:158)
java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Comment 29 Vladimir Voskresensky 2012-09-27 16:22:16 UTC
Tomas, Mila. The state described in comment 28 we've got with "uninstalled" local history functionality
Comment 30 Miloslav Metelka 2012-09-27 19:55:01 UTC
Andrew, Vladimir, thanks for observations. I've eliminated missing alreadyModified synching, could you please check whether that eliminates the problem? Thanks a lot.
http://hg.netbeans.org/jet-main/rev/7830921265b2
Comment 31 Andrew Krasny 2012-09-27 20:32:25 UTC
Miloslav,

but this change doesn't fix the problem of wrong order.. It fixes 'visibility' problem, but not synchronization in sense of what is done first... 
Depending on who wins, the value again will be unpredictably either true or false... Right?
Comment 32 Vladimir Voskresensky 2012-09-27 20:50:06 UTC
Mila, I agree with Andrew.
check-and-set change of this flag is not atomic.
I.e. 
    final boolean callNotifyModified() {
        if (!isAlreadyModified() && !documentReloading) {
            setAlreadyModified(true);

so your change will not help
Comment 33 Miloslav Metelka 2012-10-01 10:31:45 UTC
I just wanted to know whether it would have any effect on the problem as a quick fix (since I'm not able to reproduce the problem in any way) until we prepare a fix that will be stable (regarding deadlocks etc.).
Comment 34 Vladimir Voskresensky 2012-10-01 11:19:43 UTC
Mila, to see inconsistency in editor try the following:
- open file
- type something 
- in debugger put breakpoint in method CES.setAlreadyModified
- switch to IDE and very quickly do the following:
-- press Ctrl+S followed by new typing
==> you will see that setAlreadyModified was called from non EDT and when this thread finishes it's job => Save is disabled, but editor content has letter absent in file
Comment 35 Miloslav Metelka 2012-10-02 11:45:17 UTC
The SaveAction is now asynchronous by Yarda's change http://hg.netbeans.org/jet-main/rev/af7375b814a8
I have tried to call CES.callNotifyUnmodified() under readlock together with SaveAsReader's saving of doc's content so that they are in sync since CloneableOpenSupport.Env.unmarkModified() does not explicitly state that it can't be called under doc's readlock. The openide.text tests pass so after some more testing I'll possibly integrate the change.
Comment 36 Miloslav Metelka 2012-10-02 13:15:46 UTC
Unfortunately the change mentioned in the preceding comment would not work since the document impl pre-calls CES.Listener.vetoableChange() (which in turn calls callNotifyModify()) before it acquires the doc's write-lock.
Comment 37 Miloslav Metelka 2012-10-02 15:09:58 UTC
To be more precise the mentioned fix would work thank to another (later) call to callNotifyModified() in CES.Listener.insertUpdate(). First CES.Listener.vetoableChange() would be called (before write-lock is taken) calling callNotifyModified() and this would possibly be reverted by SaveAsReader which calls callNotifyUnmodified(). But once the document acquires its write-lock (SaveAsReader finishes) there will be another callNotifyModified() and this one will finally mark the file as modified.
 However the first callNotifyModified() from Listener.vetoableChange() without doc's lock is not very nice. There are no particular constraints for Env.markModified() and Env.markUnmodified() but Env.markModified() may throw UserQuestionException so it should ideally hold no locks or only locks that should not collide with existing locks so I've added an extra LOCK_NOTIFY_MODIFIED.
 Yardo could you please take a look at the current fix and possibly suggest any better solution? Thanks.
http://hg.netbeans.org/jet-main/rev/cca344bd527f
Comment 38 Quality Engineering 2012-10-03 02:42:35 UTC
Integrated into 'main-golden', will be available in build *201210030002* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/cca344bd527f
User: Miloslav Metelka <mmetelka@netbeans.org>
Log: #218626 - Editor is not writing to file.
Comment 39 Miloslav Metelka 2012-10-03 08:48:00 UTC
Unfortunately the notifyModified() inside the LOCK_NOTIFY_MODIFIED causes a deadlock of NotifyModifiedOnNbEditorLikeKitTest so I will possibly rollback or modify the fix.
Comment 40 Miloslav Metelka 2012-10-03 08:58:01 UTC
Created attachment 125276 [details]
Deadlock of the test
Comment 41 Miloslav Metelka 2012-10-03 09:50:04 UTC
I have examined the test and I have disabled the document modifications from Env.markModified() in the test. I think that they have no practical use and since the markModified() gets in fact called from doc.insertString(offset, String, attrs)/remove(offset, len) the offsets in these methods would be invalidated by the modifications performed in markModified(). Anyway I'll talk to Yarda once he'll be back from JavaOne regarding this.

http://hg.netbeans.org/jet-main/rev/27890251046f