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 23407 - EDIT command attempts to save read-only files, and does not wait until execution finishes
Summary: EDIT command attempts to save read-only files, and does not wait until execut...
Status: VERIFIED FIXED
Alias: None
Product: obsolete
Classification: Unclassified
Component: vcscore (show other bugs)
Version: 3.x
Hardware: All All
: P2 blocker (vote)
Assignee: Martin Entlicher
URL:
Keywords:
Depends on:
Blocks: 31913
  Show dependency tree
 
Reported: 2002-05-13 13:59 UTC by frank
Modified: 2003-07-16 15:23 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Patch on org.netbeans.modules.vcscore.VcsAction.java revision 1.64 (1.43 KB, patch)
2002-05-13 14:08 UTC, frank
Details | Diff
The contextual diff, that fix this problem. (3.33 KB, patch)
2003-04-01 16:11 UTC, Martin Entlicher
Details | Diff
The binary patch. Copy to <NB-install>/modules/autoload/patches/org-netbeans-modules-vcscore/ folder. (65.15 KB, application/octet-stream)
2003-04-01 16:13 UTC, Martin Entlicher
Details
Full Thread Dump on 1 CPU kernel (20.21 KB, text/plain)
2003-04-04 11:22 UTC, dmladek
Details

Note You need to log in before you can comment on or make changes to this bug.
Description frank 2002-05-13 13:59:55 UTC
The EDIT command, which is called when editing read-only 
files, tries to save the files before execution (see 
VcsAction.java). However, attempts to save read-only files 
generally fail.
Also, the command does not wait until it is finished. 
Because of this the lock() method in VcsFileSystem.java 
may conclude that a file is not writable, while the EDIT 
command is still busy making the file writable...
Comment 1 frank 2002-05-13 14:08:23 UTC
Created attachment 5713 [details]
Patch on org.netbeans.modules.vcscore.VcsAction.java revision 1.64
Comment 2 Martin Entlicher 2002-05-13 16:39:52 UTC
Well, the patch is O.K., but I wonder why is it needed?

1) Why it is a problem, that there is an attempt to save read-only
files? They are read-only, thus can not be modified. When they are not
modified there is no attempt to save them. Can you please describe the
conditions when the problem arise?

2)  the lock() method in VcsFileSystem.java 
    may conclude that a file is not writable, while the EDIT 
    command is still busy making the file writable...
Yes, I'm not sure I can block the lock() method for a long time.
Execution of the EDIT command may take a lot of time. Thus currently
lock() keeps failing as long as the file is not writable. Maybe we
should assure, that the EDIT command will be executed just once and
not in every attempt to call lock().

Comment 3 Martin Entlicher 2002-05-14 09:42:26 UTC
Downgrading to P3, it does not have a destructive impact.

Please elaborate more on what situation/testcase cause a problem.
Thanks.
Comment 4 frank 2002-05-14 10:16:04 UTC
The situation is this:
We have a DataObject that is modified, and an attempt is 
done to write the associated FileObject.  At that time the 
file is still read-only.

The EDIT command attempts to save the read-only files 
prior to execution, which results in a loop causing a 
stack overflow.
This happens as follows:
The attempt to write the FileObject triggers a call to the 
lock() method of the VcsFileSystem. This, in turn, 
triggers the execution of the EDIT command, by means of a 
call to VcsAction.doEdit().  This method first tries to 
save the file. This results (for our DataObject) the 
FileObject to be saved. This triggers a call to the lock() 
method on the file system, triggering execution of the 
EDIT command, and so on, until we get a stack overflow.

With regard to 'blocking' the lock() call: doesn't the code
in my proposed patch just do that?
And if the EDIT command's effect would be to make the file 
writable, then for that file it will only be executed on 
the first call to lock(). This makes sure that for 
subsequent calls to lock() the EDIT command is no longer 
executed.
Comment 5 Jiri Kovalsky 2002-05-14 10:25:48 UTC
I apologize for my ignorance, but how can read-only file get modified
? I probably don't get something obvious here ... :-)
Comment 6 frank 2002-05-14 10:30:58 UTC
It is not the read-only file that is modified. What *is* 
modified is the DataObjectthat is associated with the 
file. That DataObject has a SaveCookie; the SaveCookie 
takes care of writing to the FileObject.
Comment 7 Martin Entlicher 2002-05-14 14:49:19 UTC
O.K. now I get it. Thanks for the description. I will test, whether
the blocking of lock() for a long time will not cause any problems in
the IDE and integrate the patch.
Comment 8 Martin Entlicher 2002-05-23 14:10:00 UTC
I was now in attepmt to commit your patch, but I was curius why there
was already the code, that waited for the command to finish. And I've
found version 1.11 of VcsAction, where the code was commented with the
message "Do not wait for EDIT command to finish, since it leads to
deadlock."

I've fixed the first part of the issue - there will be no attempt to
save the file before the Edit command.

I'll fix the second part later, the lock() method should remember all
running EDIT and LOCK commands and do not execute them if one is
already running for the given file. It will NOT wait for them to
finish. This should not cause any problems.

Comment 9 Martin Entlicher 2002-06-04 13:01:04 UTC
Fixed in dev build on Jun 5.
VcsFileSystem.lock() method remembers all running EDIT and LOCK
commands and takes care of not executing a command if one is already
running for the given file.
Comment 10 Martin Entlicher 2002-06-06 17:26:19 UTC
Reopening, since this behavior is not really solving the original
problem. The problem is, that you want to write to a file, but it's
read-only. The EDIT command gets executed, but lock() doesn't wait for
it and you get the IOException. But you don't know, that the command
finish after some time and you can write then.

So, I can implement the blocking lock(), that's not a problem, but I'm
afraid of consequences it may have on the rest of the system. This
behavior caused some deadlock in the past, but unfortunately I do not
have the thread dump. Thus I'll implement the blocking lock() and test
it as much as possible to verify, that it does not cause any problems.
Comment 11 Marek Grummich 2002-07-22 11:55:10 UTC
Set target milestone to TBD
Comment 12 Richard Gregor 2003-03-07 12:40:02 UTC
Fix of this is not so trivial and will need further investigation. So
rescheduling to future.
Comment 13 Martin Entlicher 2003-04-01 15:47:57 UTC
Since this blocks issue #31913, I'm increasing the priority.
The fix is not hard. After the fix of issue #31643 the deadlock I was
worry about should not occur.

So, I'm going to fix it in the main trunk...
Comment 14 Martin Entlicher 2003-04-01 16:08:01 UTC
The bug is fixed in the main trunk:

/cvs/vcscore/src/org/netbeans/modules/vcscore/VcsFileSystem.java,v 
<--  VcsFileSystem.java
new revision: 1.217; previous revision: 1.216

The FileObject.lock() and UserQuestionException.confirmed() will wait
till the command that change the writable state finish.
Comment 15 Martin Entlicher 2003-04-01 16:11:54 UTC
Created attachment 9635 [details]
The contextual diff, that fix this problem.
Comment 16 Martin Entlicher 2003-04-01 16:13:34 UTC
Created attachment 9637 [details]
The binary patch. Copy to <NB-install>/modules/autoload/patches/org-netbeans-modules-vcscore/ folder.
Comment 17 dmladek 2003-04-04 11:22:53 UTC
Created attachment 9701 [details]
Full Thread Dump on 1 CPU kernel
Comment 18 dmladek 2003-04-04 11:24:30 UTC
Oupsss:-\
Please, ignore my previous attachment/comment !!!
______________________________________________________________________
... it would had come to different issue #31913 :-(
Sorry for confusing you
Comment 19 _ ttran 2003-04-04 11:54:59 UTC
should we consider fixing this for 3.5?  It's P2 but filed before the
cut-off day
Comment 20 Martin Entlicher 2003-04-04 14:30:37 UTC
Probably yes. This is also necessary for fix of issue #31913.
I'll attach text and binary patch...
Comment 21 Martin Entlicher 2003-04-04 14:36:52 UTC
Well, the diffs & patch is already there, I've overlooked them.
So see the attachments above.
Comment 22 Tomas Zezula 2003-04-04 15:24:56 UTC
The patch is OK and solves our issue.
Comment 23 _ ttran 2003-04-04 16:41:53 UTC
approved for 3.5
Comment 24 Martin Entlicher 2003-04-04 17:16:04 UTC
Thanks for the review and approval. The problem is fixed in release35
branch:

/cvs/vcscore/src/org/netbeans/modules/vcscore/VcsFileSystem.java,v 
<--  VcsFileSystem.java
new revision: 1.207.2.8; previous revision: 1.207.2.7
Comment 25 Jiri Kovalsky 2003-07-16 15:23:04 UTC
I see this as fixed and verify it. If you Frank encounter the problem
again, reopen the bug with further elaboration. Verified in Sun ONE
Studio 5.0 Standard Edition build #030528.