diff options
author | Matthias Sohn | 2018-01-02 09:33:31 +0000 |
---|---|---|
committer | Matthias Sohn | 2019-01-04 01:25:57 +0000 |
commit | 336f868f0fb4e8599d55f5d47a621be97ed903c9 (patch) | |
tree | fd18f4255a09937aa5999dffedb439be898e0df6 /org.eclipse.egit.ui.test/src | |
parent | 0649f38bf999d4a8e33f0ddf6ff2f7924afd62cd (diff) | |
download | egit-336f868f0fb4e8599d55f5d47a621be97ed903c9.tar.gz egit-336f868f0fb4e8599d55f5d47a621be97ed903c9.tar.xz egit-336f868f0fb4e8599d55f5d47a621be97ed903c9.zip |
Replace FileInputStream and FileOutputStream with static Files methods
FileInputStream and FileOutputStream rely on finalize() method to ensure
resources are closed. This implies they are added to the finalizer queue
which causes additional work for the JVM GC process.
This is an open bug on the OpenJDK [1] and the recommended workaround is
to use the Files.newInputStream and Files.newOutputStream static methods
instead.
[1] https://bugs.openjdk.java.net/browse/JDK-8080225
Change-Id: I59e72d0a12d70396a5cf558029c13e2a1b0d5741
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Signed-off-by: Michael Keppler <Michael.Keppler@gmx.de>
Diffstat (limited to 'org.eclipse.egit.ui.test/src')
3 files changed, 10 insertions, 11 deletions
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/BranchAndResetActionTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/BranchAndResetActionTest.java index d701d66242..9a984b58d2 100644 --- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/BranchAndResetActionTest.java +++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/BranchAndResetActionTest.java @@ -23,9 +23,9 @@ import static org.junit.Assert.fail; import java.io.ByteArrayInputStream; import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; +import java.nio.file.Files; import java.util.ArrayList; import org.eclipse.core.resources.IFile; @@ -138,17 +138,16 @@ public class BranchAndResetActionTest extends LocalRepositoryTestCase { test.create(new ByteArrayInputStream(new byte[0]), false, null); File testFile = new File(test.getLocation().toString()); assertTrue(testFile.exists()); - FileInputStream fis = new FileInputStream(testFile); - try { + try (InputStream fis = Files.newInputStream(testFile.toPath())) { FileUtils.delete(testFile); return; } catch (IOException e) { // the test makes sense only if deletion of // a file with open stream fails } finally { - fis.close(); - if (testFile.exists()) + if (testFile.exists()) { FileUtils.delete(testFile); + } } final Image folderImage = PlatformUI.getWorkbench().getSharedImages() .getImage(ISharedImages.IMG_OBJ_FOLDER); diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/synchronize/SynchronizeViewGitChangeSetModelTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/synchronize/SynchronizeViewGitChangeSetModelTest.java index cb5fe6f141..990baf6116 100644 --- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/synchronize/SynchronizeViewGitChangeSetModelTest.java +++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/synchronize/SynchronizeViewGitChangeSetModelTest.java @@ -29,8 +29,8 @@ import static org.junit.Assert.assertTrue; import java.io.BufferedWriter; import java.io.ByteArrayInputStream; import java.io.File; -import java.io.FileOutputStream; import java.io.OutputStreamWriter; +import java.nio.file.Files; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; @@ -257,7 +257,7 @@ public class SynchronizeViewGitChangeSetModelTest extends File root = new File(getTestDirectory(), REPO1); File nonWorkspace = new File(root, name); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter( - new FileOutputStream(nonWorkspace), "UTF-8")); + Files.newOutputStream(nonWorkspace.toPath()), "UTF-8")); writer.append("file content"); writer.close(); @@ -283,7 +283,7 @@ public class SynchronizeViewGitChangeSetModelTest extends File root = new File(getTestDirectory(), REPO1); File nonWorkspace = new File(root, name); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter( - new FileOutputStream(nonWorkspace), "UTF-8")); + Files.newOutputStream(nonWorkspace.toPath()), "UTF-8")); writer.append(content); writer.close(); // TODO Synchronize currently shows "No changes" when the only thing that has diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/synchronize/SynchronizeViewWorkspaceModelTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/synchronize/SynchronizeViewWorkspaceModelTest.java index 2449d28fac..0d247919a5 100644 --- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/synchronize/SynchronizeViewWorkspaceModelTest.java +++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/synchronize/SynchronizeViewWorkspaceModelTest.java @@ -27,8 +27,8 @@ import static org.junit.Assert.assertTrue; import java.io.BufferedWriter; import java.io.ByteArrayInputStream; import java.io.File; -import java.io.FileOutputStream; import java.io.OutputStreamWriter; +import java.nio.file.Files; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; @@ -297,7 +297,7 @@ public class SynchronizeViewWorkspaceModelTest extends AbstractSynchronizeViewTe File root = new File(getTestDirectory(), REPO1); File nonWorkspace = new File(root, name); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter( - new FileOutputStream(nonWorkspace), "UTF-8")); + Files.newOutputStream(nonWorkspace.toPath()), "UTF-8")); writer.append("file content"); writer.close(); @@ -320,7 +320,7 @@ public class SynchronizeViewWorkspaceModelTest extends AbstractSynchronizeViewTe File root = new File(getTestDirectory(), REPO1); File nonWorkspace = new File(root, name); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter( - new FileOutputStream(nonWorkspace), "UTF-8")); + Files.newOutputStream(nonWorkspace.toPath()), "UTF-8")); writer.append(content); writer.close(); |