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 186165 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]
Tests 1
bug_332543-tests.patch (text/plain), 12.00 KB, created by
James Blackburn
on 2011-01-06 09:05:50 EST
(
hide
)
Description:
Tests 1
Filename:
MIME Type:
Creator:
James Blackburn
Created:
2011-01-06 09:05:50 EST
Size:
12.00 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.core.tests.resources >Index: src/org/eclipse/core/tests/internal/filesystem/wrapper/WrapperFileStore.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/filesystem/wrapper/WrapperFileStore.java,v >retrieving revision 1.4 >diff -u -r1.4 WrapperFileStore.java >--- src/org/eclipse/core/tests/internal/filesystem/wrapper/WrapperFileStore.java 20 May 2009 23:50:57 -0000 1.4 >+++ src/org/eclipse/core/tests/internal/filesystem/wrapper/WrapperFileStore.java 6 Jan 2011 13:49:17 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2006, 2008 IBM Corporation and others. >+ * Copyright (c) 2006, 2011 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -7,6 +7,7 @@ > * > * Contributors: > * IBM Corporation - initial API and implementation >+ * James Blackburn (Broadcom Corp.) > *******************************************************************************/ > package org.eclipse.core.tests.internal.filesystem.wrapper; > >@@ -28,6 +29,19 @@ > this.baseStore = baseStore; > } > >+ public static IFileStore newInstance(Class<? extends WrapperFileStore> clazz, IFileStore baseStore) { >+ try { >+ return clazz.getConstructor(IFileStore.class).newInstance(baseStore); >+ } catch (Exception e) { >+ // Test infrastructure failure... >+ throw new Error(e); >+ } >+ } >+ >+ protected IFileStore createNewWrappedStore(IFileStore store) { >+ return newInstance(getClass(), store); >+ } >+ > public IFileInfo[] childInfos(int options, IProgressMonitor monitor) throws CoreException { > return baseStore.childInfos(options, monitor); > } >@@ -40,7 +54,7 @@ > IFileStore[] childStores = baseStore.childStores(options, monitor); > for (int i = 0; i < childStores.length; i++) > // replace ordinary file store with wrapper version >- childStores[i] = new WrapperFileStore(childStores[i]); >+ childStores[i] = createNewWrappedStore(childStores[i]); > return childStores; > } > >@@ -73,15 +87,15 @@ > } > > public IFileStore getChild(IPath path) { >- return new WrapperFileStore(baseStore.getChild(path)); >+ return createNewWrappedStore(baseStore.getChild(path)); > } >- >+ > public IFileStore getFileStore(IPath path) { >- return new WrapperFileStore(baseStore.getFileStore(path)); >+ return createNewWrappedStore(baseStore.getFileStore(path)); > } > > public IFileStore getChild(String name) { >- return new WrapperFileStore(baseStore.getChild(name)); >+ return createNewWrappedStore(baseStore.getChild(name)); > } > > public IFileSystem getFileSystem() { >@@ -94,7 +108,7 @@ > > public IFileStore getParent() { > IFileStore baseParent = baseStore.getParent(); >- return baseParent == null ? null : new WrapperFileStore(baseParent); >+ return baseParent == null ? null : createNewWrappedStore(baseParent); > } > > public int hashCode() { >Index: src/org/eclipse/core/tests/internal/filesystem/wrapper/WrapperFileSystem.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/filesystem/wrapper/WrapperFileSystem.java,v >retrieving revision 1.1 >diff -u -r1.1 WrapperFileSystem.java >--- src/org/eclipse/core/tests/internal/filesystem/wrapper/WrapperFileSystem.java 27 Mar 2006 23:00:24 -0000 1.1 >+++ src/org/eclipse/core/tests/internal/filesystem/wrapper/WrapperFileSystem.java 6 Jan 2011 13:49:17 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2006 IBM Corporation and others. >+ * Copyright (c) 2006, 2011 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -7,6 +7,7 @@ > * > * Contributors: > * IBM Corporation - initial API and implementation >+ * James Blackburn (Broadcom Corp.) > *******************************************************************************/ > package org.eclipse.core.tests.internal.filesystem.wrapper; > >@@ -22,27 +23,50 @@ > /** > * A simple file system implementation that acts as a wrapper around the > * local file system. >+ * <p> >+ * Also allows tests to inject a custom FileStore template class (derived from >+ * {@link WrapperFileStore}). Tests can use {@link #setCustomFileStore(Class)} >+ * to override default {@link WrapperFileStore} behaviour. >+ * </p> > */ > public class WrapperFileSystem extends FileSystem { > >- private static final IFileStore NULL_ROOT = EFS.getNullFileSystem().getStore(Path.ROOT); >+ protected static final IFileStore NULL_ROOT = EFS.getNullFileSystem().getStore(Path.ROOT); > > private static final String SCHEME_WRAPPED = "wrapped"; > >- private static WrapperFileSystem instance; >+ private static volatile WrapperFileSystem instance; >+ >+ /** Custom file-store wrapper */ >+ private static volatile Class<? extends WrapperFileStore> customFS = WrapperFileStore.class; > > public static URI getBasicURI(URI wrappedURI) { > Assert.isLegal(SCHEME_WRAPPED.equals(wrappedURI.getScheme())); > return URI.create(wrappedURI.getQuery()); > } > >- public static WrapperFileSystem getInstance() { >- WrapperFileSystem tmpInstance = instance; >- if (tmpInstance != null) >- return tmpInstance; >+ public static synchronized WrapperFileSystem getInstance() { >+ if (instance != null) >+ return instance; > return instance = new WrapperFileSystem(); > } > >+ /** >+ * Use fs as the WrapperFileStore to use in this filesystem. >+ * Allows tests to easily override existing IFileStore behaviour. >+ * By extending {@link WrapperFileStore} conditions difficult to simulate >+ * on the LocalFileSystem can be provoked. >+ * >+ * @param fs filestore, or null to use default {@link WrapperFileStore} >+ * based implementation. >+ */ >+ public static void setCustomFileStore(Class<? extends WrapperFileStore> fs) { >+ if (fs == null) >+ customFS = WrapperFileStore.class; >+ else >+ customFS = fs; >+ } >+ > public static URI getWrappedURI(URI baseURI) { > try { > return new URI(SCHEME_WRAPPED, null, baseURI.getPath(), baseURI.toString(), null); >@@ -69,6 +93,6 @@ > CoreTest.log(ResourceTest.PI_RESOURCES_TESTS, e); > return NULL_ROOT; > } >- return new WrapperFileStore(baseStore); >+ return WrapperFileStore.newInstance(customFS, baseStore); > } > } >Index: src/org/eclipse/core/tests/resources/ResourceTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ResourceTest.java,v >retrieving revision 1.25 >diff -u -r1.25 ResourceTest.java >--- src/org/eclipse/core/tests/resources/ResourceTest.java 20 Jan 2010 15:21:01 -0000 1.25 >+++ src/org/eclipse/core/tests/resources/ResourceTest.java 6 Jan 2011 13:49:17 -0000 >@@ -773,6 +773,7 @@ > try { > os = new FileOutputStream(osFile); > os.write(newContent.getBytes("UTF8")); >+ os.close(); > } finally { > FileUtil.safeClose(os); > } >Index: src/org/eclipse/core/tests/resources/regression/AllTests.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/AllTests.java,v >retrieving revision 1.44 >diff -u -r1.44 AllTests.java >--- src/org/eclipse/core/tests/resources/regression/AllTests.java 5 Jan 2011 15:08:26 -0000 1.44 >+++ src/org/eclipse/core/tests/resources/regression/AllTests.java 6 Jan 2011 13:49:17 -0000 >@@ -59,6 +59,7 @@ > suite.addTest(Bug_288315.suite()); > suite.addTest(Bug_329836.suite()); > suite.addTest(Bug_331445.suite()); >+ suite.addTest(Bug_332543.suite()); > suite.addTest(IFileTest.suite()); > suite.addTest(IFolderTest.suite()); > suite.addTest(IProjectTest.suite()); >Index: src/org/eclipse/core/tests/resources/regression/Bug_332543.java >=================================================================== >RCS file: src/org/eclipse/core/tests/resources/regression/Bug_332543.java >diff -N src/org/eclipse/core/tests/resources/regression/Bug_332543.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/tests/resources/regression/Bug_332543.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,108 @@ >+/******************************************************************************* >+ * Copyright (c) 2011 Broadcom Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * James Blackburn (Broadcom Corp.) - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.core.tests.resources.regression; >+ >+import java.io.*; >+import java.net.URI; >+import junit.framework.Test; >+import junit.framework.TestSuite; >+import org.eclipse.core.filesystem.IFileStore; >+import org.eclipse.core.filesystem.URIUtil; >+import org.eclipse.core.resources.*; >+import org.eclipse.core.runtime.*; >+import org.eclipse.core.tests.internal.filesystem.wrapper.WrapperFileStore; >+import org.eclipse.core.tests.internal.filesystem.wrapper.WrapperFileSystem; >+import org.eclipse.core.tests.resources.ResourceTest; >+ >+/** >+ * This tests that I/O Exception on OuptuStream#close() after IFile#setContents is correctly reported. >+ */ >+public class Bug_332543 extends ResourceTest { >+ >+ public static Test suite() { >+ return new TestSuite(Bug_332543.class); >+ } >+ >+ /** >+ * Wrapper FS which throws an IOException when someone >+ * closes an output stream... >+ */ >+ public static class IOErrOnCloseFileStore extends WrapperFileStore { >+ public IOErrOnCloseFileStore(IFileStore store) { >+ super(store); >+ } >+ >+ public OutputStream openOutputStream(int options, IProgressMonitor monitor) throws CoreException { >+ OutputStream os = super.openOutputStream(options, monitor); >+ os = new BufferedOutputStream(os) { >+ public void close() throws java.io.IOException { >+ // We close the output stream (so there aren't issues deleting the project during tear-down) >+ super.close(); >+ // But we also throw IOException as if the operation had failed. >+ throw new IOException("Whoops I dunno how to close!"); >+ } >+ }; >+ return os; >+ } >+ } >+ >+ @Override >+ protected void setUp() throws Exception { >+ super.setUp(); >+ } >+ >+ @Override >+ protected void tearDown() throws Exception { >+ WrapperFileSystem.setCustomFileStore(null); >+ super.tearDown(); >+ } >+ >+ public void testBug() throws Exception { >+ IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); >+ >+ String proj_name = getUniqueString(); >+ IPath proj_loc = root.getLocation().append(proj_name); >+ URI proj_uri = WrapperFileSystem.getWrappedURI(URIUtil.toURI(proj_loc)); >+ >+ IProjectDescription desc = ResourcesPlugin.getWorkspace().newProjectDescription(proj_name); >+ desc.setLocationURI(proj_uri); >+ // Create the project on the wrapped file system >+ IProject project = root.getProject(desc.getName()); >+ project.create(desc, getMonitor()); >+ >+ // Create a file in the project >+ IFile f = project.getFile("foo.txt"); >+ ensureExistsInFileSystem(f); >+ >+ // Set our evil IOException on close() fs. >+ WrapperFileSystem.setCustomFileStore(IOErrOnCloseFileStore.class); >+ >+ // Now open the project >+ project.open(getMonitor()); >+ >+ // Try #setContents on an existing file >+ try { >+ f.setContents(new ByteArrayInputStream("Random".getBytes()), false, true, getMonitor()); >+ fail("1.0"); >+ } catch (CoreException e) { >+ // This is expected. >+ } >+ >+ // Try create on a non-existent file >+ f = project.getFile("foo1.txt"); >+ try { >+ f.create(new ByteArrayInputStream("Random".getBytes()), false, getMonitor()); >+ fail("2.0"); >+ } catch (CoreException e) { >+ // This is expected. >+ } >+ } >+}
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