Bug 7390 - Editing and saving read-only .java source file may cause lost of data
Summary: Editing and saving read-only .java source file may cause lost of data
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.0   Edit
Hardware: PC Windows 2000
: P2 major (vote)
Target Milestone: 2.0 M3   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-01-09 11:52 EST by Milan Fort CLA
Modified: 2002-03-13 10:44 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Milan Fort CLA 2002-01-09 11:52:18 EST
Reported for Eclipse integration build 20020108.
I thing the Eclipse must protect read-only files from editing (not only when 
saving, in editor too). Now there is this problem which is critical for us:

1) setting test.java attribute read-only
2) starting Eclipse with workspace linked to file test.java
3) opening Eclipse editor with test.java
4) making changes in this editor
5) trying save (by toolbar icon save)
6) dialog "Save could not be completed. Reason: Core exception: Could not write 
to read-only file: /markus1/src/markus/test1/Test.java", submited by button OK 
and not saving file.
7) close Eclipse editor
8) open Eclipse editor again and editor shows changed code in 4)!
9) close Eclipse editor
10) file on disk is old, but in some Eclipse cache is changed
11) setting test.java attribute read-only to false
12) editing test.java with external editor (or may be check out from SourceSafe)
13) open Eclipse editor and editor shows changed code in 4), not from 12)!
14) closing Eclipse editor
15) using right mouse button on test.java file in packages window - item 
Refresh from local
16) open Eclipse editor and editor still shows changed code in 4), not from 12)!
17) closing Eclipse
18) starting Eclipse
19) open Eclipse editor and editor now shows changed code from 12)!

Its very dangerous for us bcause we are working with SourceSafe and checking 
files (copying, protecting files by read-only attributes) very offen.
Comment 1 Dirk Baeumer CLA 2002-01-10 05:12:25 EST
One possibility for this behaviour is that the file is open in another 
perspective. To verify this case you can use Window->Switch to Editor. If the 
editor shows up two or more times, you will get the described behaviour.

Need to investigate in a better handling of read only files in this case.
Comment 2 Dirk Baeumer CLA 2002-01-15 04:05:54 EST
Comments provided by Milan Fort (Milan.Fort@bsc.cz)

I read your comment and investigated that I have only one perspective with
editor.

When I open read-only file, I can edit it and than close by X. In dialog I
say "No save changes" and everything is ok, when I open file again, its
still original (from time before I changed it).

But When I open read-only file, editing it and than close by X and dialog I
say "Save changes", than i get error message "Save could not be completed.
Reason: Core exception: Could not write to read-only file: ..." AND when I
open file again, its changed! When i now change attribute of file to
writtable, I can save data from editor to file and replace original file on
disk.
Comment 3 Kai-Uwe Maetzel CLA 2002-02-01 09:54:24 EST
Only the Java editor exhibits this behavior. It's not shown by the default text 
editor. So it seems that it's a Java model issue. Suspect offending code in
CommitWorkingCopyOperation.executeOperation:
 original.getBuffer().setContents(copy.getBuffer().getCharacters());
 original.save(fMonitor, fForce);

The save call should be surrounded by a finally clause resetting the original's 
buffer.
Comment 4 Markus Oellinger CLA 2002-02-07 10:15:30 EST
I think that there are two problems:

1) when saving fails, the state is inconsistent since what eclipse thinks is 
the current state is not what is reflected on the hardisk

2) the editor does not prevent you from editing read-only files

While problem 1) is rather subtle, problem 2) should be easier to tackle and 
would also help avoiding most of the problems described here.
I also think that it is annoying if you're working with a VCS that treats non-
checked-out files as read-only (like clearcase snapshot views do).
Comment 5 Philipe Mulet CLA 2002-02-12 07:24:21 EST
Only the in-memory buffer got corrupted, and needs to be corrected in case an 
exception occurred while setting the buffer.

Also added a pre-check in operation verify() code so as to recognize this 
scenario upfront.
Comment 6 Philipe Mulet CLA 2002-03-13 10:44:18 EST
Removed the precheck in #verify() since ClearCase repo does change the read 
only flag on save request.