Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSarika Sinha2015-03-03 06:30:46 -0500
committerSarika Sinha2015-03-03 06:30:46 -0500
commit25611f0b960f8297cf41ec2a2ffe7d49c22209aa (patch)
tree87156c58215bd21bb8a456eb5ea0f607c6bebc10
parent9e0b67e5552fec7597bc1da9d9bc705816275409 (diff)
downloadeclipse.platform.debug-25611f0b960f8297cf41ec2a2ffe7d49c22209aa.tar.gz
eclipse.platform.debug-25611f0b960f8297cf41ec2a2ffe7d49c22209aa.tar.xz
eclipse.platform.debug-25611f0b960f8297cf41ec2a2ffe7d49c22209aa.zip
Bug 461219 - Compile warnings in official buildI20150303-0800
-rw-r--r--org.eclipse.debug.core/.settings/org.eclipse.jdt.core.prefs2
-rw-r--r--org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchManager.java130
-rw-r--r--org.eclipse.debug.core/core/org/eclipse/debug/internal/core/XMLMemento.java9
-rw-r--r--org.eclipse.debug.ui/.settings/org.eclipse.jdt.core.prefs3
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/ResourceExtender.java4
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/importexport/launchconfigurations/ExportLaunchConfigurationsWizardPage.java18
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationManager.java15
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/console/ProcessConsole.java10
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/LaunchView.java25
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/variables/VariablesView.java25
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/ExportBreakpointsOperation.java25
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/ImportBreakpointsOperation.java39
12 files changed, 127 insertions, 178 deletions
diff --git a/org.eclipse.debug.core/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.debug.core/.settings/org.eclipse.jdt.core.prefs
index cb08f9df6..854ba028d 100644
--- a/org.eclipse.debug.core/.settings/org.eclipse.jdt.core.prefs
+++ b/org.eclipse.debug.core/.settings/org.eclipse.jdt.core.prefs
@@ -35,7 +35,7 @@ org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=
org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
org.eclipse.jdt.core.compiler.problem.emptyStatement=warning
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
-org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=ignore
+org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=error
org.eclipse.jdt.core.compiler.problem.fallthroughCase=error
org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled
org.eclipse.jdt.core.compiler.problem.fieldHiding=warning
diff --git a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchManager.java b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchManager.java
index 0d77b6204..7ecf979fe 100644
--- a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchManager.java
+++ b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchManager.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2013 IBM Corporation and others.
+ * Copyright (c) 2000, 2015 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
@@ -797,75 +797,79 @@ public class LaunchManager extends PlatformObject implements ILaunchManager, IRe
//read piped data on Win 95, 98, and ME
Properties p= new Properties();
File file= new File(fileName);
- InputStream stream = new BufferedInputStream(new FileInputStream(file));
- p.load(stream);
- stream.close();
- if (!file.delete()) {
- file.deleteOnExit(); // if delete() fails try again on VM close
- }
- for (Entry<Object, Object> entry : p.entrySet()) {
- // Win32's environment variables are case insensitive. Put everything
- // to uppercase so that (for example) the "PATH" variable will match
- // "pAtH" correctly on Windows.
- String key = (String) entry.getKey();
- //no need to cast value
- cache.put(key, (String) p.get(key));
+ try(InputStream stream = new BufferedInputStream(new FileInputStream(file))){
+ p.load(stream);
+ if (!file.delete()) {
+ file.deleteOnExit(); // if delete() fails try again on VM close
+ }
+ for (Entry<Object, Object> entry : p.entrySet()) {
+ // Win32's environment variables are case insensitive. Put everything
+ // to uppercase so that (for example) the "PATH" variable will match
+ // "pAtH" correctly on Windows.
+ String key = (String) entry.getKey();
+ //no need to cast value
+ cache.put(key, (String) p.get(key));
+ }
}
} else {
//read process directly on other platforms
//we need to parse out matching '{' and '}' for function declarations in .bash environments
// pattern is [func name]=() { and we must find the '}' on its own line with no trailing ';'
- InputStream stream = process.getInputStream();
+ try (InputStream stream = process.getInputStream();
InputStreamReader isreader = new InputStreamReader(stream);
- BufferedReader reader = new BufferedReader(isreader);
- String line = reader.readLine();
- String key = null;
- String value = null;
- String newLine = System.getProperty("line.separator"); //$NON-NLS-1$
- while (line != null) {
- int func = line.indexOf("=()"); //$NON-NLS-1$
- if(func > 0) {
- key = line.substring(0, func);
- //scan until we find the closing '}' with no following chars
- value = line.substring(func+1);
- while(line != null && !line.equals("}")) { //$NON-NLS-1$
- line = reader.readLine();
- if(line != null) {
- value += newLine + line;
+ BufferedReader reader = new BufferedReader(isreader)) {
+ String line = reader.readLine();
+ String key = null;
+ String value = null;
+ String newLine = System.getProperty("line.separator"); //$NON-NLS-1$
+ while (line != null) {
+ int func = line.indexOf("=()"); //$NON-NLS-1$
+ if (func > 0) {
+ key = line.substring(0, func);
+ // scan until we find the closing '}' with no
+ // following chars
+ value = line.substring(func + 1);
+ while (line != null && !line.equals("}")) { //$NON-NLS-1$
+ line = reader.readLine();
+ if (line != null) {
+ value += newLine + line;
+ }
}
- }
- line = reader.readLine();
- }
- else {
- int separator = line.indexOf('=');
- if (separator > 0) {
- key = line.substring(0, separator);
- value = line.substring(separator + 1);
line = reader.readLine();
- if(line != null) {
- // this line has a '=' read ahead to check next line for '=', might be broken on more than one line
- // also if line starts with non-identifier - it is remainder of previous variable
- while (line.indexOf('=') < 0 || (line.length()>0 && !Character.isJavaIdentifierStart(line.charAt(0)))) {
- value += newLine + line;
- line = reader.readLine();
- if(line == null) {
- //if next line read is the end of the file quit the loop
- break;
+ }
+ else {
+ int separator = line.indexOf('=');
+ if (separator > 0) {
+ key = line.substring(0, separator);
+ value = line.substring(separator + 1);
+ line = reader.readLine();
+ if (line != null) {
+ // this line has a '=' read ahead to check
+ // next line for '=', might be broken on
+ // more than one line
+ // also if line starts with non-identifier -
+ // it is remainder of previous variable
+ while (line.indexOf('=') < 0 || (line.length() > 0 && !Character.isJavaIdentifierStart(line.charAt(0)))) {
+ value += newLine + line;
+ line = reader.readLine();
+ if (line == null) {
+ // if next line read is the end of
+ // the file quit the loop
+ break;
+ }
}
}
}
}
- }
- if(key != null) {
- cache.put(key, value);
- key = null;
- value = null;
- }
- else {
- line = reader.readLine();
+ if (key != null) {
+ cache.put(key, value);
+ key = null;
+ value = null;
+ } else {
+ line = reader.readLine();
+ }
}
}
- reader.close();
}
} catch (IOException e) {
// Native environment-fetching code failed.
@@ -2632,15 +2636,13 @@ public class LaunchManager extends PlatformObject implements ILaunchManager, IRe
* @since 3.4.0
*/
private void copyFile(File in, File out) throws IOException {
- FileInputStream fis = new FileInputStream(in);
- FileOutputStream fos = new FileOutputStream(out);
- byte[] buf = new byte[1024];
- int i = 0;
- while((i = fis.read(buf)) != -1) {
- fos.write(buf, 0, i);
+ try (FileInputStream fis = new FileInputStream(in); FileOutputStream fos = new FileOutputStream(out)) {
+ byte[] buf = new byte[1024];
+ int i = 0;
+ while ((i = fis.read(buf)) != -1) {
+ fos.write(buf, 0, i);
+ }
}
- fis.close();
- fos.close();
}
/**
diff --git a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/XMLMemento.java b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/XMLMemento.java
index 9b98e0b20..5e29625a2 100644
--- a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/XMLMemento.java
+++ b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/XMLMemento.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2013 IBM Corporation and others.
+ * Copyright (c) 2000, 2015 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
@@ -447,12 +447,9 @@ public final class XMLMemento {
* @throws IOException if there is a problem serializing the document to the stream.
*/
public void save(Writer writer) throws IOException {
- DOMWriter out = new DOMWriter(writer);
- try {
+ try (DOMWriter out = new DOMWriter(writer)) {
out.print(element);
- } finally {
- out.close();
- }
+ }
}
/**
diff --git a/org.eclipse.debug.ui/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.debug.ui/.settings/org.eclipse.jdt.core.prefs
index 091dbe0d4..854ba028d 100644
--- a/org.eclipse.debug.ui/.settings/org.eclipse.jdt.core.prefs
+++ b/org.eclipse.debug.ui/.settings/org.eclipse.jdt.core.prefs
@@ -35,7 +35,7 @@ org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=
org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
org.eclipse.jdt.core.compiler.problem.emptyStatement=warning
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
-org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=ignore
+org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=error
org.eclipse.jdt.core.compiler.problem.fallthroughCase=error
org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled
org.eclipse.jdt.core.compiler.problem.fieldHiding=warning
@@ -110,6 +110,7 @@ org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=warning
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled
+org.eclipse.jdt.core.compiler.problem.unusedExceptionParameter=ignore
org.eclipse.jdt.core.compiler.problem.unusedImport=error
org.eclipse.jdt.core.compiler.problem.unusedLabel=warning
org.eclipse.jdt.core.compiler.problem.unusedLocal=warning
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/ResourceExtender.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/ResourceExtender.java
index aec606b2e..347d1aa34 100644
--- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/ResourceExtender.java
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/ResourceExtender.java
@@ -56,11 +56,9 @@ public class ResourceExtender extends PropertyTester {
IPath path= editorInput.getPath();
File file= path.toFile();
if (file.exists()) {
- try {
- FileReader reader= new FileReader(file);
+ try (FileReader reader = new FileReader(file)) {
IContentType contentType= Platform.getContentTypeManager().getContentType((String)expectedValue);
IContentDescription description= contentType.getDescriptionFor(reader, IContentDescription.ALL);
- reader.close();
if (description != null) {
return matchesContentType(description.getContentType(), (String)expectedValue);
}
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/importexport/launchconfigurations/ExportLaunchConfigurationsWizardPage.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/importexport/launchconfigurations/ExportLaunchConfigurationsWizardPage.java
index b4f0079bb..c5c25cbd8 100644
--- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/importexport/launchconfigurations/ExportLaunchConfigurationsWizardPage.java
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/importexport/launchconfigurations/ExportLaunchConfigurationsWizardPage.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2013 IBM Corporation and others.
+ * Copyright (c) 2007, 2015 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
@@ -20,7 +20,6 @@ import java.util.List;
import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.filesystem.IFileStore;
-
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -40,7 +39,6 @@ import org.eclipse.debug.internal.ui.IDebugHelpContextIds;
import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
import org.eclipse.debug.internal.ui.SWTFactory;
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchCategoryFilter;
-
import org.eclipse.debug.ui.DebugUITools;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.dialogs.MessageDialog;
@@ -442,14 +440,12 @@ public class ExportLaunchConfigurationsWizardPage extends WizardPage {
* @since 3.5
*/
protected void copyFile(IFileStore in, File out) throws CoreException, IOException {
- BufferedInputStream is = new BufferedInputStream(in.openInputStream(EFS.NONE, null));
- BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(out));
- byte[] buf = new byte[1024];
- int i = 0;
- while((i = is.read(buf)) != -1) {
- os.write(buf, 0, i);
+ try (BufferedInputStream is = new BufferedInputStream(in.openInputStream(EFS.NONE, null)); BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(out))) {
+ byte[] buf = new byte[1024];
+ int i = 0;
+ while ((i = is.read(buf)) != -1) {
+ os.write(buf, 0, i);
+ }
}
- is.close();
- os.close();
}
}
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationManager.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationManager.java
index d2788ec3b..08f9135af 100644
--- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationManager.java
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationManager.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2013 IBM Corporation and others.
+ * Copyright (c) 2000, 2015 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
@@ -472,9 +472,9 @@ public class LaunchConfigurationManager implements ILaunchListener, ISavePartici
File file = new File(osHistoryPath);
file.createNewFile();
- FileOutputStream stream = new FileOutputStream(file);
- stream.write(xml.getBytes("UTF8")); //$NON-NLS-1$
- stream.close();
+ try (FileOutputStream stream = new FileOutputStream(file)) {
+ stream.write(xml.getBytes("UTF8")); //$NON-NLS-1$
+ }
}
}
@@ -491,11 +491,10 @@ public class LaunchConfigurationManager implements ILaunchListener, ISavePartici
if (!file.exists()) {
return;
}
- InputStream stream= null;
+
Element rootHistoryElement= null;
- try {
+ try (InputStream stream = new BufferedInputStream(new FileInputStream(file))) {
// Parse the history file
- stream = new BufferedInputStream(new FileInputStream(file));
try {
DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
parser.setErrorHandler(new DefaultHandler());
@@ -506,8 +505,6 @@ public class LaunchConfigurationManager implements ILaunchListener, ISavePartici
} catch (ParserConfigurationException e) {
DebugUIPlugin.log(e);
return;
- } finally {
- stream.close();
}
} catch (IOException exception) {
DebugUIPlugin.log(exception);
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/console/ProcessConsole.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/console/ProcessConsole.java
index ef2b50f81..016e17432 100644
--- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/console/ProcessConsole.java
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/console/ProcessConsole.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2014 IBM Corporation and others.
+ * Copyright (c) 2000, 2015 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
@@ -178,10 +178,8 @@ public class ProcessConsole extends IOConsole implements IConsole, IDebugEventSe
DebugUIPlugin.log(e);
}
if (message != null) {
- try {
- IOConsoleOutputStream stream = newOutputStream();
+ try (IOConsoleOutputStream stream = newOutputStream()) {
stream.write(message);
- stream.close();
} catch (IOException e) {
DebugUIPlugin.log(e);
}
@@ -203,10 +201,8 @@ public class ProcessConsole extends IOConsole implements IConsole, IDebugEventSe
message = MessageFormat.format(ConsoleMessages.ProcessConsole_3, new Object[] { fStdInFile });
}
if (message != null) {
- try {
- IOConsoleOutputStream stream = newOutputStream();
+ try (IOConsoleOutputStream stream = newOutputStream()) {
stream.write(message);
- stream.close();
} catch (IOException e) {
DebugUIPlugin.log(e);
}
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/LaunchView.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/LaunchView.java
index 1d08d4f88..1b924ac76 100644
--- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/LaunchView.java
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/LaunchView.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2013 IBM Corporation and others.
+ * Copyright (c) 2000, 2015 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
@@ -906,18 +906,12 @@ public class LaunchView extends AbstractDebugView
IPreferenceStore store = DebugUIPlugin.getDefault().getPreferenceStore();
String string = store.getString(PREF_STATE_MEMENTO);
if(string.length() > 0) {
- ByteArrayInputStream bin = new ByteArrayInputStream(string.getBytes());
- InputStreamReader reader = new InputStreamReader(bin);
- try {
+ try (ByteArrayInputStream bin = new ByteArrayInputStream(string.getBytes()); InputStreamReader reader = new InputStreamReader(bin)) {
XMLMemento stateMemento = XMLMemento.createReadRoot(reader);
setMemento(stateMemento);
} catch (WorkbenchException e) {
- } finally {
- try {
- reader.close();
- bin.close();
- } catch (IOException e){}
- }
+ } catch (IOException e1) {
+ }
}
IMemento mem = getMemento();
@@ -966,10 +960,7 @@ public class LaunchView extends AbstractDebugView
public void partDeactivated(IWorkbenchPart part) {
String id = part.getSite().getId();
if (id.equals(getSite().getId())) {
- ByteArrayOutputStream bout = new ByteArrayOutputStream();
- OutputStreamWriter writer = new OutputStreamWriter(bout);
-
- try {
+ try (ByteArrayOutputStream bout = new ByteArrayOutputStream(); OutputStreamWriter writer = new OutputStreamWriter(bout);) {
XMLMemento memento = XMLMemento.createWriteRoot("DebugViewMemento"); //$NON-NLS-1$
saveViewerState(memento);
memento.save(writer);
@@ -978,12 +969,6 @@ public class LaunchView extends AbstractDebugView
String xmlString = bout.toString();
store.putValue(PREF_STATE_MEMENTO, xmlString);
} catch (IOException e) {
- } finally {
- try {
- writer.close();
- bout.close();
- } catch (IOException e) {
- }
}
}
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/variables/VariablesView.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/variables/VariablesView.java
index 1e43e7e4a..b9790f1a4 100644
--- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/variables/VariablesView.java
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/variables/VariablesView.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2013 IBM Corporation and others.
+ * Copyright (c) 2000, 2015 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
@@ -566,18 +566,12 @@ public class VariablesView extends AbstractDebugView implements IDebugContextLis
IPreferenceStore store = DebugUIPlugin.getDefault().getPreferenceStore();
String string = store.getString(PREF_STATE_MEMENTO);
if(string.length() > 0) {
- ByteArrayInputStream bin = new ByteArrayInputStream(string.getBytes());
- InputStreamReader reader = new InputStreamReader(bin);
- try {
+ try (ByteArrayInputStream bin = new ByteArrayInputStream(string.getBytes()); InputStreamReader reader = new InputStreamReader(bin);) {
XMLMemento stateMemento = XMLMemento.createReadRoot(reader);
setMemento(stateMemento);
} catch (WorkbenchException e) {
- } finally {
- try {
- reader.close();
- bin.close();
- } catch (IOException e){}
- }
+ } catch (IOException e1) {
+ }
}
IMemento mem = getMemento();
// check the weights to makes sure they are valid -- bug 154025
@@ -619,10 +613,7 @@ public class VariablesView extends AbstractDebugView implements IDebugContextLis
public void partDeactivated(IWorkbenchPart part) {
String id = part.getSite().getId();
if (id.equals(getSite().getId())) {
- ByteArrayOutputStream bout = new ByteArrayOutputStream();
- OutputStreamWriter writer = new OutputStreamWriter(bout);
-
- try {
+ try (ByteArrayOutputStream bout = new ByteArrayOutputStream(); OutputStreamWriter writer = new OutputStreamWriter(bout);) {
XMLMemento memento = XMLMemento.createWriteRoot("VariablesViewMemento"); //$NON-NLS-1$
saveViewerState(memento);
memento.save(writer);
@@ -631,12 +622,6 @@ public class VariablesView extends AbstractDebugView implements IDebugContextLis
String xmlString = bout.toString();
store.putValue(PREF_STATE_MEMENTO, xmlString);
} catch (IOException e) {
- } finally {
- try {
- writer.close();
- bout.close();
- } catch (IOException e) {
- }
}
}
super.partDeactivated(part);
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/ExportBreakpointsOperation.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/ExportBreakpointsOperation.java
index 4f425053e..f6c4cd455 100644
--- a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/ExportBreakpointsOperation.java
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/ExportBreakpointsOperation.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2014 IBM Corporation and others.
+ * Copyright (c) 2005, 2015 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
@@ -31,7 +31,6 @@ import org.eclipse.debug.internal.ui.importexport.breakpoints.IImportExportConst
import org.eclipse.debug.internal.ui.importexport.breakpoints.ImportExportMessages;
import org.eclipse.debug.ui.IDebugUIConstants;
import org.eclipse.jface.operation.IRunnableWithProgress;
-
import org.eclipse.ui.IMemento;
import org.eclipse.ui.IWorkingSet;
import org.eclipse.ui.IWorkingSetManager;
@@ -89,10 +88,9 @@ public class ExportBreakpointsOperation implements IRunnableWithProgress {
public void run(IProgressMonitor monitor) throws InvocationTargetException {
SubMonitor localmonitor = SubMonitor.convert(monitor, ImportExportMessages.ExportOperation_0, fBreakpoints.length);
XMLMemento memento = XMLMemento.createWriteRoot(IImportExportConstants.IE_NODE_BREAKPOINTS);
- Writer writer = fWriter;
- try {
+ try (Writer writer = fWriter;) {
for (int i = 0; i < fBreakpoints.length; i++) {
- if(localmonitor.isCanceled()) {
+ if (localmonitor.isCanceled()) {
return;
}
IBreakpoint breakpoint = fBreakpoints[i];
@@ -142,9 +140,13 @@ public class ExportBreakpointsOperation implements IRunnableWithProgress {
localmonitor.worked(1);
}
if (writer == null) {
- writer = new OutputStreamWriter(new FileOutputStream(fFileName), "UTF-8"); //$NON-NLS-1$
- }
- memento.save(writer);
+ try (Writer outWriter = new OutputStreamWriter(new FileOutputStream(fFileName), "UTF-8")) { //$NON-NLS-1$
+ memento.save(outWriter);
+ }
+ } else {
+ memento.save(writer);
+ }
+
} catch (CoreException e) {
throw new InvocationTargetException(e);
} catch (IOException e) {
@@ -152,13 +154,6 @@ public class ExportBreakpointsOperation implements IRunnableWithProgress {
}
finally {
localmonitor.done();
- if(writer != null) {
- try {
- writer.close();
- } catch (IOException e) {
- throw new InvocationTargetException(e);
- }
- }
}
}
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/ImportBreakpointsOperation.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/ImportBreakpointsOperation.java
index 06b25b443..48e809373 100644
--- a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/ImportBreakpointsOperation.java
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/ImportBreakpointsOperation.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2013 IBM Corporation and others.
+ * Copyright (c) 2005, 2015 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
@@ -160,14 +160,27 @@ public class ImportBreakpointsOperation implements IRunnableWithProgress {
@Override
public void run(final IProgressMonitor monitor) throws InvocationTargetException {
SubMonitor localmonitor = SubMonitor.convert(monitor, ImportExportMessages.ImportOperation_0, 1);
- Reader reader = null;
try {
+ XMLMemento memento = null;
if (fBuffer == null) {
- reader = new InputStreamReader(new FileInputStream(fFileName), "UTF-8"); //$NON-NLS-1$
+ try (Reader reader = new InputStreamReader(new FileInputStream(fFileName), "UTF-8")) { //$NON-NLS-1$
+ memento = XMLMemento.createReadRoot(reader);
+ } catch (FileNotFoundException e) {
+ throw new InvocationTargetException(e, MessageFormat.format("Breakpoint import file not found: {0}", new Object[] { //$NON-NLS-1$
+ fFileName }));
+ } catch (UnsupportedEncodingException e) {
+ throw new InvocationTargetException(e, MessageFormat.format("The import file was written in non-UTF-8 encoding.", new Object[] { //$NON-NLS-1$
+ fFileName }));
+ } catch (IOException e) {
+ throw new InvocationTargetException(e);
+ }
} else {
- reader = new StringReader(fBuffer.toString());
+ try (Reader reader = new StringReader(fBuffer.toString())) {
+ memento = XMLMemento.createReadRoot(reader);
+ } catch (IOException e) {
+ throw new InvocationTargetException(e);
+ }
}
- XMLMemento memento = XMLMemento.createReadRoot(reader);
IMemento[] nodes = memento.getChildren(IImportExportConstants.IE_NODE_BREAKPOINT);
IWorkspaceRoot workspace = ResourcesPlugin.getWorkspace().getRoot();
localmonitor.setWorkRemaining(nodes.length);
@@ -217,28 +230,12 @@ public class ImportBreakpointsOperation implements IRunnableWithProgress {
fManager.addBreakpoints(fAdded.toArray(new IBreakpoint[fAdded.size()]));
}
}
- catch(FileNotFoundException e) {
- throw new InvocationTargetException(e,
- MessageFormat.format("Breakpoint import file not found: {0}", new Object[] { fFileName })); //$NON-NLS-1$
- }
- catch (UnsupportedEncodingException e) {
- throw new InvocationTargetException(e,
- MessageFormat.format("The import file was written in non-UTF-8 encoding.", new Object[] { fFileName })); //$NON-NLS-1$
- }
catch(CoreException ce) {
throw new InvocationTargetException(ce,
MessageFormat.format("There was a problem importing breakpoints from: {0}", new Object[] { fFileName })); //$NON-NLS-1$
}
finally {
localmonitor.done();
- if(reader != null) {
- try {
- reader.close();
- }
- catch (IOException e) {
- throw new InvocationTargetException(e);
- }
- }
}
}

Back to the top