Bug 576019 - Use try with resource and multi-catch in PDE wherever
possible
Change-Id: I29c91b5cab7c085d7703845430609d2693c9d2c0
Signed-off-by: Vikas Chandra <Vikas.Chandra@in.ibm.com>
Reviewed-on: https://git.eclipse.org/r/c/pde/eclipse.pde.build/+/185498
Tested-by: PDE Bot <pde-bot@eclipse.org>
diff --git a/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/AntLogAdapter.java b/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/AntLogAdapter.java
index 21dbaac..cf57972 100644
--- a/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/AntLogAdapter.java
+++ b/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/AntLogAdapter.java
@@ -57,13 +57,7 @@
log(element);
}
}
- } catch (IllegalArgumentException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (InvocationTargetException e) {
+ } catch (IllegalArgumentException | IllegalAccessException | InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
diff --git a/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/FeatureGenerator.java b/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/FeatureGenerator.java
index 72f6af0..917a867 100644
--- a/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/FeatureGenerator.java
+++ b/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/FeatureGenerator.java
@@ -361,7 +361,7 @@
File file = new File(directory, Constants.FEATURE_FILENAME_DESCRIPTOR);
OutputStream output = new BufferedOutputStream(new FileOutputStream(file));
XMLWriter writer = new XMLWriter(output);
- try {
+ try (writer) {
Map<String, String> parameters = new LinkedHashMap<>();
Dictionary<String, String> environment = new Hashtable<>(3);
@@ -480,8 +480,6 @@
writer.printTag("includes", parameters, true, true, true); //$NON-NLS-1$
}
writer.endTag(FEATURE);
- } finally {
- writer.close();
}
createBuildProperties(directory);
diff --git a/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/packager/FetchFileGenerator.java b/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/packager/FetchFileGenerator.java
index cea1ecd..3af3968 100644
--- a/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/packager/FetchFileGenerator.java
+++ b/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/packager/FetchFileGenerator.java
@@ -101,9 +101,6 @@
selectedFiles.put("toUnzip", collectedFiles); //$NON-NLS-1$
try (OutputStream stream = new BufferedOutputStream(new FileOutputStream(workingDirectory + '/' + DEFAULT_PACKAGER_DIRECTORY_FILENAME_DESCRIPTOR))) {
selectedFiles.store(stream, null);
- } catch (FileNotFoundException e) {
- String message = NLS.bind(Messages.exception_writingFile, workingDirectory + '/' + DEFAULT_PACKAGER_DIRECTORY_FILENAME_DESCRIPTOR);
- throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_WRITING_FILE, message, e));
} catch (IOException e) {
String message = NLS.bind(Messages.exception_writingFile, workingDirectory + '/' + DEFAULT_PACKAGER_DIRECTORY_FILENAME_DESCRIPTOR);
throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_WRITING_FILE, message, e));
diff --git a/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/packager/PackageConfigScriptGenerator.java b/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/packager/PackageConfigScriptGenerator.java
index cd8977d..0db7ef8 100644
--- a/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/packager/PackageConfigScriptGenerator.java
+++ b/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/packager/PackageConfigScriptGenerator.java
@@ -166,9 +166,6 @@
try (InputStream propertyStream = new BufferedInputStream(new FileInputStream(packagingPropertiesLocation))) {
packagingProperties.load(propertyStream);
- } catch (FileNotFoundException e) {
- String message = NLS.bind(Messages.exception_readingFile, packagingPropertiesLocation);
- throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_READING_FILE, message, e));
} catch (IOException e) {
String message = NLS.bind(Messages.exception_readingFile, packagingPropertiesLocation);
throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_READING_FILE, message, e));
diff --git a/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/packager/UnzipperGenerator.java b/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/packager/UnzipperGenerator.java
index c677734..fa61b60 100644
--- a/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/packager/UnzipperGenerator.java
+++ b/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/packager/UnzipperGenerator.java
@@ -64,9 +64,6 @@
} finally {
propertyStream.close();
}
- } catch (FileNotFoundException e) {
- // String message = Policy.bind("exception.readingFile", packagingPropertiesLocation); //$NON-NLS-1$
- //// Log.throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_READING_FILE, message, e));
} catch (IOException e) {
// String message = Policy.bind("exception.readingFile", packagingPropertiesLocation); //$NON-NLS-1$
// throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_READING_FILE, message, e));
diff --git a/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/site/BuildTimeFeatureParser.java b/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/site/BuildTimeFeatureParser.java
index 047a424..1ffb9aa 100644
--- a/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/site/BuildTimeFeatureParser.java
+++ b/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/site/BuildTimeFeatureParser.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2013 IBM Corporation and others.
+ * Copyright (c) 2007, 2021 IBM Corporation and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which accompanies this distribution,
@@ -31,10 +31,8 @@
public Feature parse(URL featureURL) throws SAXException, IOException {
InputStream in = featureURL.openStream();
- try {
+ try (in) {
return super.parse(in, featureURL);
- } finally {
- in.close();
}
}
}
diff --git a/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/site/P2Utils.java b/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/site/P2Utils.java
index 9d4da9d..9f79162 100644
--- a/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/site/P2Utils.java
+++ b/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/site/P2Utils.java
@@ -54,9 +54,6 @@
infos.addAll(Arrays.asList(manipulator.loadConfiguration(new FileInputStream(bundlesTxt), root.toURI())));
if (sourceTxt.exists())
infos.addAll(Arrays.asList(manipulator.loadConfiguration(new FileInputStream(sourceTxt), root.toURI())));
- } catch (MalformedURLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
diff --git a/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/site/PDEState.java b/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/site/PDEState.java
index 688b7ea..770bfe7 100644
--- a/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/site/PDEState.java
+++ b/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/site/PDEState.java
@@ -305,9 +305,7 @@
Hashtable<String, String> result = new Hashtable<>();
result.putAll(ManifestElement.parseBundleManifest(manifestStream, null));
return result;
- } catch (IOException ioe) {
- return null;
- } catch (BundleException e) {
+ } catch (IOException | BundleException e) {
return null;
} finally {
try {
diff --git a/org.eclipse.pde.build/src_ant/org/eclipse/pde/internal/build/publisher/BrandP2Task.java b/org.eclipse.pde.build/src_ant/org/eclipse/pde/internal/build/publisher/BrandP2Task.java
index 4818d58..933c748 100644
--- a/org.eclipse.pde.build/src_ant/org/eclipse/pde/internal/build/publisher/BrandP2Task.java
+++ b/org.eclipse.pde.build/src_ant/org/eclipse/pde/internal/build/publisher/BrandP2Task.java
@@ -254,9 +254,7 @@
new File(root, "content.jar").delete(); //$NON-NLS-1$
new File(root, "artifacts.jar").delete(); //$NON-NLS-1$
FileUtils.zip(output, root, Collections.<File> emptySet(), FileUtils.createRootPathComputer(root));
- } catch (ProvisionException e) {
- throw new BuildException(e.getMessage(), e);
- } catch (IOException e) {
+ } catch (ProvisionException | IOException e) {
throw new BuildException(e.getMessage(), e);
} finally {
Utils.close(output);
diff --git a/org.eclipse.pde.build/src_ant/org/eclipse/pde/internal/build/tasks/JNLPGenerator.java b/org.eclipse.pde.build/src_ant/org/eclipse/pde/internal/build/tasks/JNLPGenerator.java
index 800a229..6629c20 100644
--- a/org.eclipse.pde.build/src_ant/org/eclipse/pde/internal/build/tasks/JNLPGenerator.java
+++ b/org.eclipse.pde.build/src_ant/org/eclipse/pde/internal/build/tasks/JNLPGenerator.java
@@ -91,9 +91,7 @@
try {
parserFactory.setNamespaceAware(true);
parser = parserFactory.newSAXParser();
- } catch (ParserConfigurationException e) {
- System.out.println(e);
- } catch (SAXException e) {
+ } catch (ParserConfigurationException | SAXException e) {
System.out.println(e);
}
setConfigInfo(configs);