Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Sohn2018-01-02 04:41:16 -0500
committerMatthias Sohn2018-01-02 04:41:16 -0500
commit8b24d5046e5f2813d8df5f1b4a13ed8f323aea23 (patch)
treee25190478747a9944d1baf5a04f8d83731cb8641
parent618dfdd09a2b0f686d4316d30ea3693d6a3f01ea (diff)
downloadegit-github-8b24d5046e5f2813d8df5f1b4a13ed8f323aea23.tar.gz
egit-github-8b24d5046e5f2813d8df5f1b4a13ed8f323aea23.tar.xz
egit-github-8b24d5046e5f2813d8df5f1b4a13ed8f323aea23.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: I2de6fc27d7fb593a946e9f6d9bb64873092e258c Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
-rw-r--r--org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/DownloadService.java8
-rw-r--r--org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/GitHubUi.java38
2 files changed, 18 insertions, 28 deletions
diff --git a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/DownloadService.java b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/DownloadService.java
index 97c44421..6e859e47 100644
--- a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/DownloadService.java
+++ b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/DownloadService.java
@@ -16,13 +16,11 @@ import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_REPOS
import static org.eclipse.egit.github.core.client.PagedRequest.PAGE_FIRST;
import static org.eclipse.egit.github.core.client.PagedRequest.PAGE_SIZE;
-import com.google.gson.reflect.TypeToken;
-
import java.io.File;
-import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
+import java.nio.file.Files;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -36,6 +34,8 @@ import org.eclipse.egit.github.core.client.PageIterator;
import org.eclipse.egit.github.core.client.PagedRequest;
import org.eclipse.egit.github.core.util.MultiPartUtils;
+import com.google.gson.reflect.TypeToken;
+
/**
* Service for accessing, creating, and deleting repositories downloads.
*
@@ -309,7 +309,7 @@ public class DownloadService extends GitHubService {
if (file == null)
throw new IllegalArgumentException("File cannot be null"); //$NON-NLS-1$
- return createDownload(repository, download, new FileInputStream(file),
+ return createDownload(repository, download, Files.newInputStream(file.toPath()),
file.length());
}
}
diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/GitHubUi.java b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/GitHubUi.java
index 1a1e00ca..49f61844 100644
--- a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/GitHubUi.java
+++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/GitHubUi.java
@@ -13,11 +13,10 @@
package org.eclipse.mylyn.internal.github.ui;
import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
+import java.nio.file.Files;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
@@ -48,7 +47,7 @@ public class GitHubUi extends AbstractUIPlugin {
/**
* Create status
- *
+ *
* @param severity
* @param message
* @return status
@@ -59,7 +58,7 @@ public class GitHubUi extends AbstractUIPlugin {
/**
* Create status
- *
+ *
* @param severity
* @param message
* @param e
@@ -71,7 +70,7 @@ public class GitHubUi extends AbstractUIPlugin {
/**
* Create error status from message
- *
+ *
* @param message
* @return status
*/
@@ -81,7 +80,7 @@ public class GitHubUi extends AbstractUIPlugin {
/**
* Create error status from message and throwable
- *
+ *
* @param message
* @param t
* @return status
@@ -92,7 +91,7 @@ public class GitHubUi extends AbstractUIPlugin {
/**
* Create error status from throwable
- *
+ *
* @param e
* @return status
*/
@@ -103,7 +102,7 @@ public class GitHubUi extends AbstractUIPlugin {
/**
* Log message and throwable as error
- *
+ *
* @param message
* @param t
*/
@@ -113,7 +112,7 @@ public class GitHubUi extends AbstractUIPlugin {
/**
* Log throwable as error
- *
+ *
* @param t
*/
public static void logError(Throwable t) {
@@ -124,7 +123,7 @@ public class GitHubUi extends AbstractUIPlugin {
/**
* Get default activator
- *
+ *
* @return plug-in
*/
public static GitHubUi getDefault() {
@@ -142,7 +141,7 @@ public class GitHubUi extends AbstractUIPlugin {
/**
* Get avatar store
- *
+ *
* @return avatar store
*/
public AvatarStore getStore() {
@@ -163,7 +162,7 @@ public class GitHubUi extends AbstractUIPlugin {
/**
* Load avatars
- *
+ *
* @param context
*/
protected void loadAvatars(BundleContext context) {
@@ -172,7 +171,7 @@ public class GitHubUi extends AbstractUIPlugin {
if (file.exists()) {
ObjectInputStream stream = null;
try {
- stream = new ObjectInputStream(new FileInputStream(file));
+ stream = new ObjectInputStream(Files.newInputStream(file.toPath()));
store = (AvatarStore) stream.readObject();
} catch (IOException e) {
logError("Error reading avatar store", e); //$NON-NLS-1$
@@ -193,7 +192,7 @@ public class GitHubUi extends AbstractUIPlugin {
/**
* Save avatars
- *
+ *
* @param context
*/
protected void saveAvatars(BundleContext context) {
@@ -201,19 +200,10 @@ public class GitHubUi extends AbstractUIPlugin {
IPath location = Platform.getStateLocation(context.getBundle());
File file = location.append(STORE_NAME).toFile();
- ObjectOutputStream stream = null;
- try {
- stream = new ObjectOutputStream(new FileOutputStream(file));
+ try (ObjectOutputStream stream = new ObjectOutputStream(Files.newOutputStream(file.toPath()))) {
stream.writeObject(this.store);
} catch (IOException e) {
logError("Error writing avatar store", e); //$NON-NLS-1$
- } finally {
- if (stream != null)
- try {
- stream.close();
- } catch (IOException ignore) {
- // Ignored
- }
}
}

Back to the top