Bug 234307 - Java Model Exception from org.eclipse.jdt.internal.core.Buffer.save(Buffer.javga:361)
Summary: Java Model Exception from org.eclipse.jdt.internal.core.Buffer.save(Buffer.ja...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.4   Edit
Hardware: PC Linux
: P3 blocker (vote)
Target Milestone: 3.4 RC3   Edit
Assignee: Jerome Lanneluc CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-05-28 02:49 EDT by Jack Fong CLA
Modified: 2008-06-04 11:00 EDT (History)
5 users (show)

See Also:
philippe_mulet: review+
frederic_fusier: review+
david_audel: review+


Attachments
Proposed fix and regression test (3.76 KB, patch)
2008-05-29 05:43 EDT, Jerome Lanneluc CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jack Fong CLA 2008-05-28 02:49:26 EDT
Build ID: eclipse-SDK-3.4RC1

Steps To Reproduce:
1.  
2.
3.


More information:
I'm only getting this exception on the linux platform.  My program works fine in Windows.

Please take a look at this exception:
Java Model Exception: Core Exception [code 368] Resource '/TestFile.java' does not exist.
        at org.eclipse.jdt.internal.core.Buffer.save(Buffer.java:384)
        at org.eclipse.jdt.internal.core.Openable.save(Openable.java:480)
        at org.eclipse.jdt.internal.core.CompilationUnit.save(CompilationUnit.java:1270)
        at foo.DumpApplication.externalize(DumpApplication.java:123)
Caused by: org.eclipse.core.internal.resources.ResourceException: Resource '/TestFile.java' does not exist.
        at org.eclipse.core.internal.resources.Resource.checkExists(Resource.java:317)
        at org.eclipse.core.internal.resources.Resource.checkAccessible(Resource .java:194)
        at org.eclipse.core.internal.resources.File.getContentDescription(File.java:277)
        at org.eclipse.jdt.internal.core.Buffer.save(Buffer.java:361)
        at org.eclipse.jdt.internal.core.Openable.save(Openable.java:480)
        at org.eclipse.jdt.internal.core.CompilationUnit.save(CompilationUnit.java:1270)
        at foo.DumpApplication.externalize(DumpApplication.java:123)

When I debug into JDT Buffer.java, I found that at line 361, we should only call:
  IContentDescription description = this.file.getContentDescription();
if this.file.exists() == true similar to line 373.
Comment 1 Thomas Hallgren CLA 2008-05-28 03:10:24 EDT
Reassigning to jdt-core-inbox since I don't think this is in any way related to the spaces project.
Comment 2 Jerome Lanneluc CLA 2008-05-29 05:34:39 EDT
Looking at the trace, it appears that it is impossible to get in this situation since Openable.save(...) first acquires a buffer which ensures that the file exists. 

In fact, this can happen if a race condition occurs: the file is deleted after the buffer is acquired, and thus the Buffer.save(...) operation fails if the encoding is "UTF-8". I was able to confirm this behavior on Jack's machine.

I entered bug 234551 to capture the race condition issue.

However one can see this issue by using IBuffer.save(...) directly. The following snippet shows the problem:

IBuffer buffer = (new WorkingCopyOwner() {}).createBuffer(
  getCompilationUnit("/P/X234307.java"));
buffer.setContents(
  "public class X234307 {\n" +
  "}"
);
IProject project = getProject("P");
String defaultCharset = project.getDefaultCharset();
try {
  project.setDefaultCharset("UTF-8", null);
  String newContents = 
    "public interface X234307 {\n" +
    "}";
  buffer.setContents(newContents);
  buffer.save(null, false/*don't force*/);
  char[] contents = Util.getFileCharContent(
    getFile("/P/X234307.java").getLocation().toFile(), null);
  assertSourceEquals("Unexpected source", newContents, new String(contents));
} finally {
  deleteBuffer(buffer); // this deletes the file as well
  project.setDefaultCharset(defaultCharset, null);
}

Since there is no workaround, and the reporter marked the bug as blocker we should fix this bug for 3.4RC3
Comment 3 Jerome Lanneluc CLA 2008-05-29 05:43:10 EDT
Created attachment 102594 [details]
Proposed fix and regression test
Comment 4 Jerome Lanneluc CLA 2008-05-29 05:44:41 EDT
Philippe, Frederic, David, can you please approve/review?
Comment 5 Frederic Fusier CLA 2008-05-29 06:08:45 EDT
Patch looks good: +1
Comment 6 David Audel CLA 2008-05-29 07:02:16 EDT
Patch looks good: +1
Comment 7 Philipe Mulet CLA 2008-05-29 09:25:19 EDT
+1 for 3.4rc3
Comment 8 Jerome Lanneluc CLA 2008-05-29 09:35:06 EDT
Fix and test released for 3.4RC3
Comment 9 Jack Fong CLA 2008-05-29 15:01:43 EDT
Tested patch and it is good.  Thank you Jerome.
Comment 10 David Audel CLA 2008-05-30 10:59:15 EDT
Verified for 3.4RC4.
Comment 11 Olivier Thomann CLA 2008-06-04 11:00:11 EDT
The copyright was not updated!