Bug 341296 - .classpath file is read-only, many modifications later and ok, can not write error
Summary: .classpath file is read-only, many modifications later and ok, can not write ...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.7   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 3.8 M5   Edit
Assignee: Markus Keller CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 368108 (view as bug list)
Depends on:
Blocks:
 
Reported: 2011-03-29 19:59 EDT by MG CLA
Modified: 2012-01-24 11:55 EST (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description MG CLA 2011-03-29 19:59:27 EDT
Build Identifier: 20100917-0705

It would be great if instead of telling you at the end of modifying a 100 classpath entries and clicking ok and then ignoring all those changes it would either remind you up front or give you the option to overwrite.

Reproducible: Always
Comment 1 Prakash Rangaraj CLA 2011-03-29 22:28:27 EDT
Can you give clear steps to reproduce?
Comment 2 Dani Megert CLA 2011-03-30 11:33:49 EDT
Why is your .classpath file read-only?
Comment 3 MG CLA 2012-01-08 14:55:29 EST
The version control system I work with keeps the files readonly on retrieval -
stupid I know.  Anyway I always seem to forget to make the classpath
non-readonly before using the project properties java build path and spending a
bunch of time modifying it only to have eclipse discard my changes when I hit
save as the file is readonly.  

Steps to repro:

1. Make your .classpath file readonly
2. Open your eclipse project
3. Project->Properties->Java Build Path->Remove an entry->Ok

Error Dialog:

'Setting build path' has encountered a problem.  File projectname/.classpath is read-only.
Comment 4 Stephan Herrmann CLA 2012-01-08 15:00:00 EST
*** Bug 368108 has been marked as a duplicate of this bug. ***
Comment 5 Dani Megert CLA 2012-01-09 04:24:40 EST
This works if the team provider implements validateEdit(...) correctly. For example, when using watch/edit mode in CVS, the team provider makes the file writable.

Now, for the case when there is no team provider (i.e. file not shared), validateEdit(...) asks the user, but that only happens if the client provided a context. Currently JDT Core calls validate edit with a 'null' context (see e.g. JavaProject.setSharedProperty(String, String).

JDT Core needs to check whether they have a context (e.g. a shell) and if not, whether it makes sense to allow passing such a context by the client.
Comment 6 Dani Megert CLA 2012-01-09 04:25:55 EST
Marking as minor/P5 since
1. For shared files, the Team Provider should deal with this.
2. Users should not mark the .classpath file read-only themselves.
Comment 7 Dani Megert CLA 2012-01-09 04:26:51 EST
(In reply to comment #3)
> The version control system I work with keeps the files readonly on retrieval -
> stupid I know.

Please file a bug against the provide of your Team plug-in.
Comment 8 MG CLA 2012-01-09 16:11:20 EST
The problem is that I am not using the perforce team provider or managing the revision control via eclipse.  I use the tools provided by the version control vendor and I don't want to be forced to use an eclipse plugin to manage the revision control.  Ideally I wouldn't be forced to use this implementation of a rcs where the files are marked readonly but I don't have that option.

But let's extend the example out.  Let's say I create a project, commit to my revision control system, and then get the source, zip and distribute out to the internet.  The files will be readonly and anyone who loads this project into eclipse isn't going to have the rcs plugin and if they modify the classpath via the ui then they will encounter the same problem.

I agree that the problem isn't major but if the fix is easy then if you'd consider normal priority I'd appreciate it.
Comment 9 Dani Megert CLA 2012-01-10 02:09:55 EST
> I agree that the problem isn't major but if the fix is easy

It depends whether JDT Core already has a context somewhere. If not, new APIs need to be define, so that it can be provided.
 
> then if you'd consider normal priority I'd appreciate it.
Sure.
Comment 10 Markus Keller CLA 2012-01-10 14:03:25 EST
> It depends whether JDT Core already has a context somewhere. If not, new APIs
> need to be define, so that it can be provided.

JDT Core doesn't have a context, but bug 160905 added a generic IWorkspace.VALIDATE_PROMPT.

Fixed in master with commit ec0896f6be6c41a0353321bffc1f242fe4e5e1b4.
Comment 11 Dani Megert CLA 2012-01-11 06:07:14 EST
(In reply to comment #10)
> > It depends whether JDT Core already has a context somewhere. If not, new APIs
> > need to be define, so that it can be provided.
> 
> JDT Core doesn't have a context, but bug 160905 added a generic
> IWorkspace.VALIDATE_PROMPT.
> 
> Fixed in master with commit ec0896f6be6c41a0353321bffc1f242fe4e5e1b4.

Nice!
Comment 12 Stephan Herrmann CLA 2012-01-24 10:37:33 EST
This looks good, mostly.

However, on Linux I still succeed to get the project into an inconsistent state:

a) mark .classpath as readonly (chmod 444 .classpath)
b) change the JRE on the projects classpath (using the prj. pref. UI)
c) get a dialog asking whether .classpath should be made writable: GOOD!
d) answer "No"
e) observe the error dialog mentioned in comment 3
f) observe that the package explorer has (most the time(?)) already updated
   the "JRE System Library" whereas the content of .classpath has not been
   changed
g) after an unsuccessful attempt to change JRE from 1.5 to 1.7 the compiler
   actually uses the 1.7 JRE as tested by referring to type AutoCloseable:
   Initially (using 1.5): error
   After unsuccessful attempt to change JRE to 1.7: no error

Is this a known limitation?
Comment 13 Markus Keller CLA 2012-01-24 11:55:06 EST
I don't think this a known limitation. Could be fixed in a separate bug if somebody cared enough. This is not a new problem and requires a malicious user.

The call to validateEdit should be pulled to the beginning of SetClasspathOperation#executeOperation(), guarded with this.canChangeResources and the other checks on rscFile in JavaProject#setSharedProperty(..), and the operation should throw a JME if the validation failed.