Bug 151022

Summary: ResourceException in buffer.save()
Product: [Eclipse Project] JDT Reporter: Roberto Scaramuzzi <birdo>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: VERIFIED INVALID QA Contact:
Severity: normal    
Priority: P3 CC: Olivier_Thomann
Version: 3.2   
Target Milestone: 3.6 M1   
Hardware: PC   
OS: Linux   
Whiteboard:

Description Roberto Scaramuzzi CLA 2006-07-18 19:16:45 EDT
The following code throws a ResourceException when the default encoding is UTF-8 (for example on Fedora Core Linux 4 and 5)

ICompilationUnit unit = a compilation unit corresponding to a file that does not exist
ICompilationUnit working_copy = (ICompilationUnit) unit.getWorkingCopy (
            null, null, null);
IBuffer buffer = working_copy.getBuffer();
buffer.setContents("blah blah");
buffer.save(null, true);

This throws a ResourceException at Buffer.java line 361
The problem is that IFile.getContentDescription throws the exception when the file does not exist.

The obvious fix is to skip the enclosing if block if the file does not exist, but the if block is there to fix another bug, so I am not sure if this is the right fix.
Comment 1 Olivier Thomann CLA 2009-06-25 14:24:52 EDT
Should not you create the unit instead of creating a working copy on a unit that doesn't have an underlying file?
For me this looks like it works as expected.
Closing as INVALID.
Please reopen if I misunderstood what you want to do.
Comment 2 Frederic Fusier CLA 2009-08-04 08:45:16 EDT
Verified for 3.6M1