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 186166 Details for
Bug 332543
IFile#setContents eats I/O Exception on close => potential file corruption
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Fix 1
bug_332543.patch (text/plain), 19.71 KB, created by
James Blackburn
on 2011-01-06 09:26:55 EST
(
hide
)
Description:
Fix 1
Filename:
MIME Type:
Creator:
James Blackburn
Created:
2011-01-06 09:26:55 EST
Size:
19.71 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.core.resources >Index: src/org/eclipse/core/internal/localstore/Bucket.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.core.resources/src/org/eclipse/core/internal/localstore/Bucket.java,v >retrieving revision 1.19 >diff -u -r1.19 Bucket.java >--- src/org/eclipse/core/internal/localstore/Bucket.java 20 Dec 2010 22:16:00 -0000 1.19 >+++ src/org/eclipse/core/internal/localstore/Bucket.java 6 Jan 2011 14:00:59 -0000 >@@ -10,6 +10,8 @@ > *******************************************************************************/ > package org.eclipse.core.internal.localstore; > >+import org.eclipse.core.internal.utils.FileUtil; >+ > import java.io.*; > import java.util.*; > import org.eclipse.core.internal.resources.ResourceException; >@@ -350,8 +352,9 @@ > writeEntryKey(destination, entry.getKey()); > writeEntryValue(destination, entry.getValue()); > } >- } finally { > destination.close(); >+ } finally { >+ FileUtil.safeClose(destination); > } > needSaving = false; > } catch (IOException ioe) { >Index: src/org/eclipse/core/internal/localstore/BucketTree.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.core.resources/src/org/eclipse/core/internal/localstore/BucketTree.java,v >retrieving revision 1.12 >diff -u -r1.12 BucketTree.java >--- src/org/eclipse/core/internal/localstore/BucketTree.java 3 Jun 2008 12:34:51 -0000 1.12 >+++ src/org/eclipse/core/internal/localstore/BucketTree.java 6 Jan 2011 14:00:59 -0000 >@@ -10,6 +10,8 @@ > *******************************************************************************/ > package org.eclipse.core.internal.localstore; > >+import org.eclipse.core.internal.utils.FileUtil; >+ > import java.io.*; > import org.eclipse.core.internal.localstore.Bucket.Visitor; > import org.eclipse.core.internal.resources.ResourceException; >@@ -139,24 +141,15 @@ > if (!versionFile.getParentFile().exists()) > versionFile.getParentFile().mkdirs(); > FileOutputStream stream = null; >- boolean failed = false; > try { > stream = new FileOutputStream(versionFile); > stream.write(current.getVersion()); >+ stream.close(); > } catch (IOException e) { >- failed = true; > String message = NLS.bind(Messages.resources_writeWorkspaceMeta, versionFile.getAbsolutePath()); > throw new ResourceException(IResourceStatus.FAILED_WRITE_METADATA, null, message, e); > } finally { >- try { >- if (stream != null) >- stream.close(); >- } catch (IOException e) { >- if (!failed) { >- String message = NLS.bind(Messages.resources_writeWorkspaceMeta, versionFile.getAbsolutePath()); >- throw new ResourceException(IResourceStatus.FAILED_WRITE_METADATA, null, message, e); >- } >- } >+ FileUtil.safeClose(stream); > } > } > >Index: src/org/eclipse/core/internal/localstore/FileSystemResourceManager.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.core.resources/src/org/eclipse/core/internal/localstore/FileSystemResourceManager.java,v >retrieving revision 1.129 >diff -u -r1.129 FileSystemResourceManager.java >--- src/org/eclipse/core/internal/localstore/FileSystemResourceManager.java 20 Dec 2010 22:16:00 -0000 1.129 >+++ src/org/eclipse/core/internal/localstore/FileSystemResourceManager.java 6 Jan 2011 14:01:00 -0000 >@@ -1091,17 +1091,12 @@ > try { > out = fileStore.openOutputStream(EFS.NONE, null); > new ModelObjectWriter().write(desc, out); >+ out.close(); > } catch (IOException e) { > String msg = NLS.bind(Messages.resources_writeMeta, target.getFullPath()); > throw new ResourceException(IResourceStatus.FAILED_WRITE_METADATA, target.getFullPath(), msg, e); > } finally { >- if (out != null) { >- try { >- out.close(); >- } catch (IOException e) { >- // ignore failure to close stream >- } >- } >+ FileUtil.safeClose(out); > } > //for backwards compatibility, ensure the old .prj file is deleted > getWorkspace().getMetaArea().clearOldDescription(target); >Index: src/org/eclipse/core/internal/localstore/SafeChunkyOutputStream.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.core.resources/src/org/eclipse/core/internal/localstore/SafeChunkyOutputStream.java,v >retrieving revision 1.9 >diff -u -r1.9 SafeChunkyOutputStream.java >--- src/org/eclipse/core/internal/localstore/SafeChunkyOutputStream.java 4 Apr 2006 20:53:47 -0000 1.9 >+++ src/org/eclipse/core/internal/localstore/SafeChunkyOutputStream.java 6 Jan 2011 14:01:00 -0000 >@@ -10,6 +10,8 @@ > *******************************************************************************/ > package org.eclipse.core.internal.localstore; > >+import org.eclipse.core.internal.utils.FileUtil; >+ > import java.io.*; > > /** >@@ -63,9 +65,10 @@ > public void succeed() throws IOException { > try { > endChunk(); >+ close(); > } finally { > isOpen = false; >- close(); >+ FileUtil.safeClose(this); > } > } > >Index: src/org/eclipse/core/internal/localstore/SafeFileOutputStream.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.core.resources/src/org/eclipse/core/internal/localstore/SafeFileOutputStream.java,v >retrieving revision 1.17 >diff -u -r1.17 SafeFileOutputStream.java >--- src/org/eclipse/core/internal/localstore/SafeFileOutputStream.java 3 Jun 2008 12:34:51 -0000 1.17 >+++ src/org/eclipse/core/internal/localstore/SafeFileOutputStream.java 6 Jan 2011 14:01:00 -0000 >@@ -86,6 +86,7 @@ > source = new BufferedInputStream(new FileInputStream(sourceFile)); > destination = new BufferedOutputStream(new FileOutputStream(destinationFile)); > transferStreams(source, destination); >+ destination.close(); > } finally { > FileUtil.safeClose(source); > FileUtil.safeClose(destination); >Index: src/org/eclipse/core/internal/resources/FileState.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/FileState.java,v >retrieving revision 1.27 >diff -u -r1.27 FileState.java >--- src/org/eclipse/core/internal/resources/FileState.java 3 Jun 2008 12:34:50 -0000 1.27 >+++ src/org/eclipse/core/internal/resources/FileState.java 6 Jan 2011 14:01:00 -0000 >@@ -10,6 +10,8 @@ > *******************************************************************************/ > package org.eclipse.core.internal.resources; > >+import org.eclipse.core.internal.utils.FileUtil; >+ > import java.io.*; > import org.eclipse.core.internal.localstore.IHistoryStore; > import org.eclipse.core.internal.utils.Messages; >@@ -53,23 +55,15 @@ > // tries to obtain a description for the file contents > IContentTypeManager contentTypeManager = Platform.getContentTypeManager(); > InputStream contents = new BufferedInputStream(getContents()); >- boolean failed = false; > try { > IContentDescription description = contentTypeManager.getDescriptionFor(contents, getName(), new QualifiedName[] {IContentDescription.CHARSET}); >+ contents.close(); > return description == null ? null : description.getCharset(); > } catch (IOException e) { >- failed = true; > String message = NLS.bind(Messages.history_errorContentDescription, getFullPath()); > throw new ResourceException(IResourceStatus.FAILED_DESCRIBING_CONTENTS, getFullPath(), message, e); > } finally { >- try { >- contents.close(); >- } catch (IOException e) { >- if (!failed) { >- String message = NLS.bind(Messages.history_errorContentDescription, getFullPath()); >- throw new ResourceException(IResourceStatus.FAILED_DESCRIBING_CONTENTS, getFullPath(), message, e); >- } >- } >+ FileUtil.safeClose(contents); > } > } > >Index: src/org/eclipse/core/internal/resources/LocalMetaArea.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/LocalMetaArea.java,v >retrieving revision 1.46 >diff -u -r1.46 LocalMetaArea.java >--- src/org/eclipse/core/internal/resources/LocalMetaArea.java 29 Nov 2010 12:10:40 -0000 1.46 >+++ src/org/eclipse/core/internal/resources/LocalMetaArea.java 6 Jan 2011 14:01:00 -0000 >@@ -12,6 +12,8 @@ > *******************************************************************************/ > package org.eclipse.core.internal.resources; > >+import org.eclipse.core.internal.utils.FileUtil; >+ > import java.io.*; > import java.net.URI; > import java.util.HashMap; >@@ -480,8 +482,9 @@ > } > } > output.succeed(); >- } finally { > dataOut.close(); >+ } finally { >+ FileUtil.safeClose(dataOut); > } > } catch (IOException e) { > String message = NLS.bind(Messages.resources_exSaveProjectLocation, target.getName()); >Index: src/org/eclipse/core/internal/resources/ModelObjectWriter.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/ModelObjectWriter.java,v >retrieving revision 1.37 >diff -u -r1.37 ModelObjectWriter.java >--- src/org/eclipse/core/internal/resources/ModelObjectWriter.java 25 Apr 2010 23:15:36 -0000 1.37 >+++ src/org/eclipse/core/internal/resources/ModelObjectWriter.java 6 Jan 2011 14:01:00 -0000 >@@ -155,9 +155,9 @@ > try { > file = new SafeFileOutputStream(location.toOSString(), tempPath); > write(object, file); >+ file.close(); > } finally { >- if (file != null) >- file.close(); >+ FileUtil.safeClose(file); > } > } > >@@ -170,8 +170,10 @@ > write(object, writer); > writer.flush(); > writer.close(); >+ if (writer.checkError()) >+ throw new IOException(); > } finally { >- output.close(); >+ FileUtil.safeClose(output); > } > } > >Index: src/org/eclipse/core/internal/resources/ProjectDescriptionReader.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/ProjectDescriptionReader.java,v >retrieving revision 1.44 >diff -u -r1.44 ProjectDescriptionReader.java >--- src/org/eclipse/core/internal/resources/ProjectDescriptionReader.java 25 Apr 2010 23:15:36 -0000 1.44 >+++ src/org/eclipse/core/internal/resources/ProjectDescriptionReader.java 6 Jan 2011 14:01:00 -0000 >@@ -12,6 +12,8 @@ > *******************************************************************************/ > package org.eclipse.core.internal.resources; > >+import org.eclipse.core.internal.utils.FileUtil; >+ > import java.io.*; > import java.net.URI; > import java.net.URISyntaxException; >@@ -946,8 +948,7 @@ > file = new BufferedInputStream(new FileInputStream(location.toFile())); > return read(new InputSource(file)); > } finally { >- if (file != null) >- file.close(); >+ FileUtil.safeClose(file); > } > } > >Index: src/org/eclipse/core/internal/resources/ProjectPreferences.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/ProjectPreferences.java,v >retrieving revision 1.63 >diff -u -r1.63 ProjectPreferences.java >--- src/org/eclipse/core/internal/resources/ProjectPreferences.java 5 Jan 2011 11:19:33 -0000 1.63 >+++ src/org/eclipse/core/internal/resources/ProjectPreferences.java 6 Jan 2011 14:01:00 -0000 >@@ -594,16 +594,13 @@ > ByteArrayOutputStream output = new ByteArrayOutputStream(); > try { > table.store(output, null); >+ output.close(); > } catch (IOException e) { > String message = NLS.bind(Messages.preferences_saveProblems, absolutePath()); > log(new Status(IStatus.ERROR, Platform.PI_RUNTIME, IStatus.ERROR, message, e)); > throw new BackingStoreException(message); > } finally { >- try { >- output.close(); >- } catch (IOException e) { >- // ignore >- } >+ FileUtil.safeClose(output); > } > final InputStream input = new BufferedInputStream(new ByteArrayInputStream(output.toByteArray())); > IWorkspaceRunnable operation = new IWorkspaceRunnable() { >Index: src/org/eclipse/core/internal/resources/SafeFileTable.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/SafeFileTable.java,v >retrieving revision 1.11 >diff -u -r1.11 SafeFileTable.java >--- src/org/eclipse/core/internal/resources/SafeFileTable.java 21 Feb 2005 23:10:23 -0000 1.11 >+++ src/org/eclipse/core/internal/resources/SafeFileTable.java 6 Jan 2011 14:01:00 -0000 >@@ -10,6 +10,8 @@ > *******************************************************************************/ > package org.eclipse.core.internal.resources; > >+import org.eclipse.core.internal.utils.FileUtil; >+ > import java.io.*; > import java.util.Properties; > import java.util.Set; >@@ -80,8 +82,9 @@ > FileOutputStream output = new FileOutputStream(target); > try { > table.store(output, "safe table"); //$NON-NLS-1$ >- } finally { > output.close(); >+ } finally { >+ FileUtil.safeClose(output); > } > } catch (IOException e) { > String message = Messages.resources_exSafeSave; >Index: src/org/eclipse/core/internal/resources/SaveManager.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/SaveManager.java,v >retrieving revision 1.108 >diff -u -r1.108 SaveManager.java >--- src/org/eclipse/core/internal/resources/SaveManager.java 29 Nov 2010 12:10:40 -0000 1.108 >+++ src/org/eclipse/core/internal/resources/SaveManager.java 6 Jan 2011 14:01:01 -0000 >@@ -1201,8 +1201,9 @@ > try { > masterTable.store(output, "master table"); //$NON-NLS-1$ > output.succeed(); >- } finally { > output.close(); >+ } finally { >+ FileUtil.safeClose(output); > } > } catch (IOException e) { > throw new ResourceException(IResourceStatus.INTERNAL_ERROR, null, NLS.bind(Messages.resources_exSaveMaster, location.toOSString()), e); >@@ -1278,8 +1279,9 @@ > try { > output.writeInt(ICoreConstants.WORKSPACE_TREE_VERSION_2); > writeTree(project, output, monitor); >- } finally { > output.close(); >+ } finally { >+ FileUtil.safeClose(output); > } > OutputStream snapOut = store.openOutputStream(EFS.NONE, monitor); > out = new ZipOutputStream(snapOut); >@@ -1295,14 +1297,13 @@ > } > out.closeEntry(); > } finally { >- in.close(); >+ FileUtil.safeClose(in); > } >+ out.close(); > } catch (IOException e) { > throw new ResourceException(IResourceStatus.FAILED_WRITE_LOCAL, snapshotPath, Messages.resources_copyProblem, e); > } finally { >- if (out!=null) { >- try { out.close(); } catch (IOException e) { /*ignore*/ } >- } >+ FileUtil.safeClose(out); > if (tmpTree!=null) tmpTree.delete(); > } > } >@@ -1322,8 +1323,9 @@ > try { > output.writeInt(ICoreConstants.WORKSPACE_TREE_VERSION_2); > writeTree(computeStatesToSave(contexts, workspace.getElementTree()), output, monitor); >- } finally { > output.close(); >+ } finally { >+ FileUtil.safeClose(output); > } > } catch (Exception e) { > String msg = NLS.bind(Messages.resources_writeWorkspaceMeta, treeLocation); >@@ -1549,12 +1551,7 @@ > if (root.getType() != IResource.ROOT) > o2 = new DataOutputStream(new SafeFileOutputStream(syncInfoLocation.toOSString(), syncInfoTempLocation.toOSString())); > } catch (IOException e) { >- if (o1 != null) >- try { >- o1.close(); >- } catch (IOException e2) { >- // ignore >- } >+ FileUtil.safeClose(o1); > message = NLS.bind(Messages.resources_writeMeta, root.getFullPath()); > throw new ResourceException(IResourceStatus.FAILED_WRITE_METADATA, root.getFullPath(), message, e); > } >@@ -1610,8 +1607,11 @@ > removeGarbage(markersOutput, markersLocation, markersTempLocation); > // if we have the workspace root the output stream will be null and we > // don't have to perform cleanup code >- if (syncInfoOutput != null) >+ if (syncInfoOutput != null) { > removeGarbage(syncInfoOutput, syncInfoLocation, syncInfoTempLocation); >+ syncInfoOutput.close(); >+ } >+ markersOutput.close(); > } catch (IOException e) { > message = NLS.bind(Messages.resources_writeMeta, root.getFullPath()); > throw new ResourceException(IResourceStatus.FAILED_WRITE_METADATA, root.getFullPath(), message, e); >@@ -1719,8 +1719,11 @@ > System.out.println("Snap SyncInfo for " + root.getFullPath() + ": " + snapTimes[1] + "ms"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ > if (markerFileSize != markersOutput.size()) > safeMarkerStream.succeed(); >- if (safeSyncInfoStream != null && syncInfoFileSize != syncInfoOutput.size()) >+ if (safeSyncInfoStream != null && syncInfoFileSize != syncInfoOutput.size()) { > safeSyncInfoStream.succeed(); >+ syncInfoOutput.close(); >+ } >+ markersOutput.close(); > } catch (IOException e) { > message = NLS.bind(Messages.resources_writeMeta, root.getFullPath()); > throw new ResourceException(IResourceStatus.FAILED_WRITE_METADATA, root.getFullPath(), message, e); >@@ -1969,9 +1972,9 @@ > output.writeUTF((String) it.next()); > for (Iterator it = additionalConfigNames.iterator(); it.hasNext();) > output.writeUTF((String) it.next()); >+ output.close(); > } finally { >- if (output != null) >- output.close(); >+ FileUtil.safeClose(output); > if (!wasImmutable) > workspace.newWorkingTree(); > } >@@ -1990,8 +1993,9 @@ > DataOutputStream output = new DataOutputStream(safe); > output.writeInt(ICoreConstants.WORKSPACE_TREE_VERSION_2); > writeTree(project, output, null); >- } finally { > safe.close(); >+ } finally { >+ FileUtil.safeClose(safe); > } > } catch (IOException e) { > String msg = NLS.bind(Messages.resources_writeMeta, project.getFullPath()); >Index: src/org/eclipse/core/internal/utils/FileUtil.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.core.resources/src/org/eclipse/core/internal/utils/FileUtil.java,v >retrieving revision 1.19 >diff -u -r1.19 FileUtil.java >--- src/org/eclipse/core/internal/utils/FileUtil.java 17 Nov 2008 04:21:23 -0000 1.19 >+++ src/org/eclipse/core/internal/utils/FileUtil.java 6 Jan 2011 14:01:01 -0000 >@@ -175,25 +175,25 @@ > * Closes a stream and ignores any resulting exception. This is useful > * when doing stream cleanup in a finally block where secondary exceptions > * are not worth logging. >+ * >+ *<p> >+ * <strong>WARNING:</strong> >+ * If the API contract requires notifying clients of I/O problems, then you <strong>must</strong> >+ * explicitly close() output streams outside of safeClose(). >+ * Some OutputStreams will defer an IOException from write() to close(). So >+ * while the writes may 'succeed', ignoring the IOExcpetion will result in silent >+ * data loss. >+ * </p> >+ * <p> >+ * This method should only be used as a fail-safe to ensure resources are not >+ * leaked. >+ * </p> >+ * See also: https://bugs.eclipse.org/bugs/show_bug.cgi?id=332543 > */ >- public static void safeClose(InputStream in) { >- try { >- if (in != null) >- in.close(); >- } catch (IOException e) { >- //ignore >- } >- } >- >- /** >- * Closes a stream and ignores any resulting exception. This is useful >- * when doing stream cleanup in a finally block where secondary exceptions >- * are not worth logging. >- */ >- public static void safeClose(OutputStream out) { >+ public static void safeClose(Closeable stream) { > try { >- if (out != null) >- out.close(); >+ if (stream != null) >+ stream.close(); > } catch (IOException e) { > //ignore > } >@@ -233,9 +233,12 @@ > String msg = NLS.bind(Messages.localstore_failedReadDuringWrite, path); > throw new ResourceException(IResourceStatus.FAILED_READ_LOCAL, new Path(path), msg, e); > } >- if (bytesRead == -1) >- break; > try { >+ if (bytesRead == -1) { >+ // Bug 332543 - ensure we don't ignore failures on close() >+ destination.close(); >+ break; >+ } > destination.write(buffer, 0, bytesRead); > } catch (IOException e) { > String msg = NLS.bind(Messages.localstore_couldNotWrite, path);
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 332543
:
186165
|
186166
|
186381