Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Keppler2019-04-28 12:12:15 -0400
committerMichael Keppler2019-05-15 06:26:39 -0400
commitba0338dadf704ce24a63cd99a22e3acac7887509 (patch)
tree1dd8c5e78d1e0ad7eebe7fffc8e2b167e13fcc3a
parent2b5d27f65957c6e0957c3571edc808ff76f2ddd7 (diff)
downloadegit-ba0338dadf704ce24a63cd99a22e3acac7887509.tar.gz
egit-ba0338dadf704ce24a63cd99a22e3acac7887509.tar.xz
egit-ba0338dadf704ce24a63cd99a22e3acac7887509.zip
Use try-finally to dispose clipboard
Clipboard uses system resources. Use try-finally there similarly as we would with any Closable. Change-Id: Ida5bd1ded9d69f904b89a739c888b21fbeaf8526 Signed-off-by: Michael Keppler <Michael.Keppler@gmx.de>
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/CreatePatchActionTest.java8
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewRepoHandlingTest.java42
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/components/RepositorySelectionPage.java17
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/fetch/FetchGerritChangePage.java10
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitCreatePatchWizard.java9
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/PasteCommand.java8
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/staging/StagingView.java6
7 files changed, 57 insertions, 43 deletions
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/CreatePatchActionTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/CreatePatchActionTest.java
index e45b98ca0..d395a9c4c 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/CreatePatchActionTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/CreatePatchActionTest.java
@@ -241,8 +241,12 @@ public class CreatePatchActionTest extends LocalRepositoryTestCase {
@Override
public void run() {
Clipboard clp = new Clipboard(Display.getCurrent());
- value[0] = (String) clp.getContents(TextTransfer.getInstance());
- clp.dispose();
+ try {
+ value[0] = (String) clp
+ .getContents(TextTransfer.getInstance());
+ } finally {
+ clp.dispose();
+ }
}
});
assertEquals(expected, value[0]);
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewRepoHandlingTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewRepoHandlingTest.java
index d332f2516..d424c0365 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewRepoHandlingTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewRepoHandlingTest.java
@@ -80,21 +80,26 @@ public class GitRepositoriesViewRepoHandlingTest extends
@Override
public void run() {
Clipboard clp = new Clipboard(Display.getCurrent());
- clp.clearContents();
- clp.setContents(new Object[] { "x" },
- new TextTransfer[] { TextTransfer.getInstance() });
- String value = (String) clp.getContents(TextTransfer
- .getInstance());
- assertEquals("Clipboard content should be x", "x", value);
-
- ContextMenuHelper.clickContextMenuSync(tree, myUtil
- .getPluginLocalizedValue("CopyPathCommand"));
- value = (String) clp.getContents(TextTransfer.getInstance());
- assertTrue("Clipboard content (" + value
- + ")should be a repository path", FileKey
- .isGitRepository(new File(value), FS.DETECTED));
-
- clp.dispose();
+ try {
+ clp.clearContents();
+ clp.setContents(new Object[] { "x" },
+ new TextTransfer[] { TextTransfer.getInstance() });
+ String value = (String) clp
+ .getContents(TextTransfer.getInstance());
+ assertEquals("Clipboard content should be x", "x", value);
+
+ ContextMenuHelper.clickContextMenuSync(tree,
+ myUtil.getPluginLocalizedValue("CopyPathCommand"));
+ value = (String) clp
+ .getContents(TextTransfer.getInstance());
+ assertTrue(
+ "Clipboard content (" + value
+ + ")should be a repository path",
+ FileKey.isGitRepository(new File(value),
+ FS.DETECTED));
+ } finally {
+ clp.dispose();
+ }
}
});
@@ -111,9 +116,9 @@ public class GitRepositoriesViewRepoHandlingTest extends
@Override
public void run() {
- Clipboard clip = null;
+ Clipboard clip = new Clipboard(
+ PlatformUI.getWorkbench().getDisplay());
try {
- clip = new Clipboard(PlatformUI.getWorkbench().getDisplay());
clip.setContents(new Object[] { repositoryFile.getPath() },
new Transfer[] { TextTransfer.getInstance() });
@@ -122,8 +127,7 @@ public class GitRepositoriesViewRepoHandlingTest extends
} catch (Exception e) {
exceptions[0] = e;
} finally {
- if (clip != null)
- clip.dispose();
+ clip.dispose();
}
}
});
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/components/RepositorySelectionPage.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/components/RepositorySelectionPage.java
index 9842ea2e9..8151bee0e 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/components/RepositorySelectionPage.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/components/RepositorySelectionPage.java
@@ -324,15 +324,18 @@ public class RepositorySelectionPage extends WizardPage implements IRepositorySe
String preset = presetUri;
if (presetUri == null) {
Clipboard clipboard = new Clipboard(Display.getCurrent());
- String text = (String) clipboard
- .getContents(TextTransfer.getInstance());
- if (text != null) {
- text = GitUrlChecker.sanitizeAsGitUrl(text);
- if (GitUrlChecker.isValidGitUrl(text)) {
- preset = text;
+ try {
+ String text = (String) clipboard
+ .getContents(TextTransfer.getInstance());
+ if (text != null) {
+ text = GitUrlChecker.sanitizeAsGitUrl(text);
+ if (GitUrlChecker.isValidGitUrl(text)) {
+ preset = text;
+ }
}
+ } finally {
+ clipboard.dispose();
}
- clipboard.dispose();
}
this.presetUri = preset;
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/fetch/FetchGerritChangePage.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/fetch/FetchGerritChangePage.java
index 884959df4..c3dee00c2 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/fetch/FetchGerritChangePage.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/fetch/FetchGerritChangePage.java
@@ -235,9 +235,13 @@ public class FetchGerritChangePage extends WizardPage {
changeRefs.clear();
});
Clipboard clipboard = new Clipboard(parent.getDisplay());
- String clipText = (String) clipboard.getContents(TextTransfer
- .getInstance());
- clipboard.dispose();
+ String clipText;
+ try {
+ clipText = (String) clipboard
+ .getContents(TextTransfer.getInstance());
+ } finally {
+ clipboard.dispose();
+ }
String defaultUri = null;
String defaultCommand = null;
String defaultChange = null;
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitCreatePatchWizard.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitCreatePatchWizard.java
index eed6e3514..449dea923 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitCreatePatchWizard.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitCreatePatchWizard.java
@@ -218,9 +218,12 @@ public class GitCreatePatchWizard extends Wizard {
public void run() {
TextTransfer plainTextTransfer = TextTransfer.getInstance();
Clipboard clipboard = new Clipboard(getShell().getDisplay());
- clipboard.setContents(new String[] { content },
- new Transfer[] { plainTextTransfer });
- clipboard.dispose();
+ try {
+ clipboard.setContents(new String[] { content },
+ new Transfer[] { plainTextTransfer });
+ } finally {
+ clipboard.dispose();
+ }
}
});
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/PasteCommand.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/PasteCommand.java
index 83db2de7c..13d2e2e7e 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/PasteCommand.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/PasteCommand.java
@@ -55,9 +55,8 @@ public class PasteCommand extends
// repository location and try to add this
String errorMessage = null;
- Clipboard clip = null;
+ Clipboard clip = new Clipboard(getShell(event).getDisplay());
try {
- clip = new Clipboard(getShell(event).getDisplay());
String content = (String) clip.getContents(TextTransfer
.getInstance());
if (content == null) {
@@ -99,10 +98,7 @@ public class PasteCommand extends
}
return null;
} finally {
- if (clip != null) {
- // we must dispose ourselves
- clip.dispose();
- }
+ clip.dispose();
if (errorMessage != null) {
Activator.showError(errorMessage, null);
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/staging/StagingView.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/staging/StagingView.java
index 63d92e5e9..bf1ea7d96 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/staging/StagingView.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/staging/StagingView.java
@@ -2193,10 +2193,10 @@ public class StagingView extends ViewPart
private void copyPathOfSelectionToClipboard(final TreeViewer viewer) {
Clipboard cb = new Clipboard(viewer.getControl().getDisplay());
- TextTransfer t = TextTransfer.getInstance();
- String text = getTextFrom(
- (IStructuredSelection) viewer.getSelection());
try {
+ TextTransfer t = TextTransfer.getInstance();
+ String text = getTextFrom(
+ (IStructuredSelection) viewer.getSelection());
if (text != null) {
cb.setContents(new Object[] { text }, new Transfer[] { t });
}

Back to the top