Bug 25184 - Operations on cu outside classpath should fail
Summary: Operations on cu outside classpath should fail
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.0   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: 2.1 M3   Edit
Assignee: Jerome Lanneluc CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-10-22 09:44 EDT by Jerome Lanneluc CLA
Modified: 2002-11-14 07:12 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 Jerome Lanneluc CLA 2002-10-22 09:44:47 EDT
Build 20021018

If you create an ICompilationUnit on a resource which is outside the project's 
classpath, all subsequent operations (except the creation of a working copy) 
should fail with a JavaModelException (status ELEMENT_DOES_NOT_EXIST)
Comment 1 Philipe Mulet CLA 2002-10-22 10:14:29 EDT
We should wait until we have some feedback on this front.
Comment 2 Philipe Mulet CLA 2002-10-30 17:09:35 EST
Current plan is to release this no later than 2.1-M3.
Comment 3 Jerome Lanneluc CLA 2002-11-08 09:42:17 EST
Fixed CompilationUnit to ensure that exists() returns false for a cu outside 
the classpath and that it cannot be opened.
Fixed WorkingCopy to allow to open a working copy on such a cu.
Comment 4 Jerome Lanneluc CLA 2002-11-12 12:42:30 EST
In case this fix needs to be undone:
1. Add the following methods to CompilationUnit:
public IResource getUnderlyingResource() throws JavaModelException {
	return getResource();
}
protected boolean parentExists(){
	return true; // tolerate units outside classpath
}
2. Move WorkingCopy.openParent() to CompilationUnit
3. Replace WorkingCopy.commit with the following contents:
/**
 * @see IWorkingCopy
 */
public void commit(boolean force, IProgressMonitor monitor) throws 
JavaModelException {
	ICompilationUnit original = (ICompilationUnit)this.getOriginalElement();
	if (original.exists()) {
		CommitWorkingCopyOperation op= new CommitWorkingCopyOperation
(this, force);
		runOperation(op, monitor);
	} else {
		IFile originalRes = (IFile)original.getResource();
		try {
			originalRes.create(
				new InputStream() {
					public int read() throws IOException {
						return -1;
					}
				},
				force,
				monitor);
		} catch (CoreException e) {
			throw new JavaModelException(e);
		}
		original.getBuffer().setContents(this.getContents());
		original.save(monitor, force);
	}
}
Comment 5 Jerome Lanneluc CLA 2002-11-12 13:04:04 EST
Actually point 3 is not needed.
Comment 6 Jerome Lanneluc CLA 2002-11-12 13:28:27 EST
Added flag CompilationUnit.FIX_BUG25184 which is set to true. To undo the fix, 
set it to false.
Comment 7 David Audel CLA 2002-11-14 07:12:03 EST
Verified.