Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Sohn2018-01-02 04:33:31 -0500
committerMatthias Sohn2019-01-03 20:25:57 -0500
commit336f868f0fb4e8599d55f5d47a621be97ed903c9 (patch)
treefd18f4255a09937aa5999dffedb439be898e0df6 /org.eclipse.egit.core.test/src
parent0649f38bf999d4a8e33f0ddf6ff2f7924afd62cd (diff)
downloadegit-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.core.test/src')
-rw-r--r--org.eclipse.egit.core.test/src/org/eclipse/egit/core/internal/indexdiff/IndexDiffCacheTest.java13
-rw-r--r--org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/internal/mapping/HistoryTest.java11
2 files changed, 7 insertions, 17 deletions
diff --git a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/internal/indexdiff/IndexDiffCacheTest.java b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/internal/indexdiff/IndexDiffCacheTest.java
index ec0cf9879..166f5f92f 100644
--- a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/internal/indexdiff/IndexDiffCacheTest.java
+++ b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/internal/indexdiff/IndexDiffCacheTest.java
@@ -16,16 +16,13 @@ import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
-import java.io.FileOutputStream;
+import java.io.OutputStream;
+import java.nio.file.Files;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import org.eclipse.core.resources.IFile;
import org.eclipse.egit.core.Activator;
-import org.eclipse.egit.core.internal.indexdiff.IndexDiffCache;
-import org.eclipse.egit.core.internal.indexdiff.IndexDiffCacheEntry;
-import org.eclipse.egit.core.internal.indexdiff.IndexDiffChangedListener;
-import org.eclipse.egit.core.internal.indexdiff.IndexDiffData;
import org.eclipse.egit.core.op.ConnectProviderOperation;
import org.eclipse.egit.core.test.GitTestCase;
import org.eclipse.egit.core.test.TestRepository;
@@ -259,11 +256,9 @@ public class IndexDiffCacheTest extends GitTestCase {
hasItem("Project-1/sub/ignore"));
IFile file = project.getProject().getFile("sub/ignore");
- FileOutputStream str = new FileOutputStream(file.getLocation().toFile());
- try {
+ try (OutputStream str = Files
+ .newOutputStream((file.getLocation().toFile().toPath()))) {
str.write("other contents".getBytes("UTF-8"));
- } finally {
- str.close();
}
// no job should be triggered for that change.
diff --git a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/internal/mapping/HistoryTest.java b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/internal/mapping/HistoryTest.java
index f0d069d3f..186d23e13 100644
--- a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/internal/mapping/HistoryTest.java
+++ b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/internal/mapping/HistoryTest.java
@@ -16,10 +16,10 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import java.io.File;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
+import java.nio.file.Files;
import java.util.Date;
import java.util.TimeZone;
@@ -90,14 +90,9 @@ public class HistoryTest extends GitTestCase {
private File createFile(String name, String content) throws IOException {
File f = new File(workDir, name);
- Writer fileWriter = null;
- try {
- fileWriter = new OutputStreamWriter(new FileOutputStream(f),
- "UTF-8");
+ try (Writer fileWriter = new OutputStreamWriter(
+ Files.newOutputStream(f.toPath()), "UTF-8")) {
fileWriter.write(content);
- } finally {
- if (fileWriter != null)
- fileWriter.close();
}
return f;
}

Back to the top