Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 102594 Details for
Bug 234307
Java Model Exception from org.eclipse.jdt.internal.core.Buffer.save(Buffer.javga:361)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Proposed fix and regression test
234307.txt (text/plain), 3.76 KB, created by
Jerome Lanneluc
on 2008-05-29 05:43:10 EDT
(
hide
)
Description:
Proposed fix and regression test
Filename:
MIME Type:
Creator:
Jerome Lanneluc
Created:
2008-05-29 05:43:10 EDT
Size:
3.76 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core >Index: model/org/eclipse/jdt/internal/core/Buffer.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/Buffer.java,v >retrieving revision 1.56 >diff -u -r1.56 Buffer.java >--- model/org/eclipse/jdt/internal/core/Buffer.java 10 Nov 2006 17:09:30 -0000 1.56 >+++ model/org/eclipse/jdt/internal/core/Buffer.java 29 May 2008 09:36:30 -0000 >@@ -17,6 +17,7 @@ > > import org.eclipse.core.resources.IFile; > import org.eclipse.core.resources.IResource; >+import org.eclipse.core.resources.IResourceStatus; > import org.eclipse.core.runtime.CoreException; > import org.eclipse.core.runtime.IProgressMonitor; > import org.eclipse.core.runtime.ISafeRunnable; >@@ -358,7 +359,15 @@ > // Special case for UTF-8 BOM files > // see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=110576 > if (encoding != null && encoding.equals(org.eclipse.jdt.internal.compiler.util.Util.UTF_8)) { >- IContentDescription description = this.file.getContentDescription(); >+ IContentDescription description; >+ try { >+ description = this.file.getContentDescription(); >+ } catch (CoreException e) { >+ if (e.getStatus().getCode() != IResourceStatus.RESOURCE_NOT_FOUND) >+ throw e; >+ // file no longer exist (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=234307 ) >+ description = null; >+ } > if (description != null && description.getProperty(IContentDescription.BYTE_ORDER_MARK) != null) { > int bomLength= IContentDescription.BOM_UTF_8.length; > byte[] bytesWithBOM= new byte[bytes.length + bomLength]; >#P org.eclipse.jdt.core.tests.model >Index: src/org/eclipse/jdt/core/tests/model/BufferTests.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/BufferTests.java,v >retrieving revision 1.20 >diff -u -r1.20 BufferTests.java >--- src/org/eclipse/jdt/core/tests/model/BufferTests.java 29 Mar 2006 04:03:07 -0000 1.20 >+++ src/org/eclipse/jdt/core/tests/model/BufferTests.java 29 May 2008 09:36:31 -0000 >@@ -13,10 +13,12 @@ > import java.util.ArrayList; > > import org.eclipse.core.resources.IFile; >+import org.eclipse.core.resources.IProject; > import org.eclipse.core.resources.IResource; > import org.eclipse.core.runtime.CoreException; > > import org.eclipse.jdt.core.*; >+ > import junit.framework.Test; > > public class BufferTests extends ModifyingResourceTests implements IBufferChangedListener { >@@ -413,6 +415,32 @@ > this.deleteBuffer(buffer); > } > } >+/* >+ * Ensure that saving a buffer on a non-yet existing resource and using the UTF-8 encoding doesn't throw an exception >+ * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=234307 ) >+ */ >+public void testSaveNonExistingUTF8() throws Exception { >+ 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 = org.eclipse.jdt.internal.compiler.util.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); >+ } >+} > /** > * Tests inserting text in the middle of a buffer. > */
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 234307
: 102594