diff --git a/apitools/org.eclipse.pde.api.tools/META-INF/MANIFEST.MF b/apitools/org.eclipse.pde.api.tools/META-INF/MANIFEST.MF index e3e6e79a2f..729b109db9 100644 --- a/apitools/org.eclipse.pde.api.tools/META-INF/MANIFEST.MF +++ b/apitools/org.eclipse.pde.api.tools/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.pde.api.tools;singleton:=true -Bundle-Version: 1.3.0.qualifier +Bundle-Version: 1.3.100.qualifier Bundle-Vendor: %providerName Bundle-Localization: plugin Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.25.0,4.0.0)", diff --git a/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/model/ApiElement.java b/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/model/ApiElement.java index 1964c6c045..0596d227dd 100644 --- a/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/model/ApiElement.java +++ b/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/model/ApiElement.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2009 IBM Corporation and others. + * Copyright (c) 2008, 2023 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -101,7 +101,11 @@ protected void setName(String newname) { * @throws CoreException */ protected void abort(String message, Throwable e) throws CoreException { - throw new CoreException(Status.error(message, e)); + throw abortException(message, e); + } + + protected CoreException abortException(String message, Throwable e) { + return new CoreException(Status.error(message, e)); } @Override diff --git a/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/model/StubArchiveApiTypeContainer.java b/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/model/StubArchiveApiTypeContainer.java index ba16713354..f609a3d8e9 100644 --- a/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/model/StubArchiveApiTypeContainer.java +++ b/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/model/StubArchiveApiTypeContainer.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2013 IBM Corporation and others. + * Copyright (c) 2009, 2023 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -94,31 +94,20 @@ public int hashCode() { @Override public byte[] getContents() throws CoreException { StubArchiveApiTypeContainer archive = (StubArchiveApiTypeContainer) getParent(); - ZipFile zipFile = archive.open(); - ZipEntry entry = zipFile.getEntry(getName()); - InputStream stream = null; - if (entry != null) { - try { - stream = zipFile.getInputStream(entry); - } catch (IOException e) { - abort("Failed to open class file: " + getTypeName() + " in archive: " + archive.fLocation, e); //$NON-NLS-1$ //$NON-NLS-2$ - return null; - } - try { - return stream.readAllBytes(); - } catch (IOException ioe) { - abort("Unable to read class file: " + getTypeName(), ioe); //$NON-NLS-1$ - return null; // never gets here - } finally { - try { - stream.close(); - } catch (IOException e) { - ApiPlugin.log(e); + try (ZipFile zipFile = archive.open()) { + ZipEntry entry = zipFile.getEntry(getName()); + if (entry != null) { + try (InputStream stream = zipFile.getInputStream(entry)) { + return stream.readAllBytes(); } } + throw abortException("Class file not found: " + getTypeName() + " in archive: " + archive.fLocation, //$NON-NLS-1$ //$NON-NLS-2$ + null); + } catch (IOException e) { + ApiPlugin.log(e); + throw abortException( + "Failed to read class file: " + getTypeName() + " in archive: " + archive.fLocation, e); //$NON-NLS-1$ //$NON-NLS-2$ } - abort("Class file not found: " + getTypeName() + " in archive: " + archive.fLocation, null); //$NON-NLS-1$ //$NON-NLS-2$ - return null; } } diff --git a/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/util/Util.java b/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/util/Util.java index 2d46adc27d..6a0b8f366a 100644 --- a/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/util/Util.java +++ b/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/util/Util.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2021 IBM Corporation and others. + * Copyright (c) 2007, 2023 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -1983,15 +1983,14 @@ public static void guntar(String zipPath, String destDirPath) throws TarExceptio new File(destDirPath, fileDir).mkdirs(); // write file File outFile = new File(destDirPath, filePath); - BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(outFile)); - int n = 0; - InputStream inputStream = tarFile.getInputStream(zEntry); - BufferedInputStream stream = new BufferedInputStream(inputStream); - while ((n = stream.read(buf)) >= 0) { - outputStream.write(buf, 0, n); + try (BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(outFile))) { + int n = 0; + try (BufferedInputStream stream = new BufferedInputStream(tarFile.getInputStream(zEntry))) { + while ((n = stream.read(buf)) >= 0) { + outputStream.write(buf, 0, n); + } + } } - outputStream.close(); - stream.close(); } } } diff --git a/ui/org.eclipse.pde.core/META-INF/MANIFEST.MF b/ui/org.eclipse.pde.core/META-INF/MANIFEST.MF index 0e32b19392..c272e39047 100644 --- a/ui/org.eclipse.pde.core/META-INF/MANIFEST.MF +++ b/ui/org.eclipse.pde.core/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %name Bundle-SymbolicName: org.eclipse.pde.core; singleton:=true -Bundle-Version: 3.17.0.qualifier +Bundle-Version: 3.17.100.qualifier Bundle-Activator: org.eclipse.pde.internal.core.PDECore Bundle-Vendor: %provider-name Bundle-Localization: plugin diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/TargetDefinitionManager.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/TargetDefinitionManager.java index 3b8b0ebe5e..a7ea986e83 100644 --- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/TargetDefinitionManager.java +++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/TargetDefinitionManager.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2012 IBM Corporation and others. + * Copyright (c) 2005, 2023 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -14,6 +14,7 @@ package org.eclipse.pde.internal.core; import java.io.IOException; +import java.io.InputStream; import java.net.URL; import java.util.Arrays; import java.util.Comparator; @@ -113,12 +114,14 @@ private boolean isValid(IConfigurationElement elem) { value = elem.getAttribute("definition"); //$NON-NLS-1$ String symbolicName = elem.getDeclaringExtension().getContributor().getName(); URL url = getResourceURL(symbolicName, value); - try { - if (url != null && url.openStream().available() > 0) { - return true; + if (url != null) { + try (InputStream s = url.openStream()) { + if (s.available() > 0) { + return true; + } + } catch (IOException e) { + // file does not exist } - } catch (IOException e) { - // file does not exist } return false; } diff --git a/ui/org.eclipse.pde.core/src_ant/org/eclipse/pde/internal/core/ant/ConvertSchemaToHTML.java b/ui/org.eclipse.pde.core/src_ant/org/eclipse/pde/internal/core/ant/ConvertSchemaToHTML.java index f43b422e98..8d05ef4bd9 100644 --- a/ui/org.eclipse.pde.core/src_ant/org/eclipse/pde/internal/core/ant/ConvertSchemaToHTML.java +++ b/ui/org.eclipse.pde.core/src_ant/org/eclipse/pde/internal/core/ant/ConvertSchemaToHTML.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2017 IBM Corporation and others. + * Copyright (c) 2000, 2023 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -212,8 +212,8 @@ private String getPluginID() { File OSGiFile = new File(file.getParentFile(), ICoreConstants.BUNDLE_FILENAME_DESCRIPTOR); if (OSGiFile.exists()) { - try { - Map headers = ManifestElement.parseBundleManifest(new FileInputStream(OSGiFile), new HeaderMap<>()); + try (FileInputStream manifestStream = new FileInputStream(OSGiFile)) { + Map headers = ManifestElement.parseBundleManifest(manifestStream, new HeaderMap<>()); String value = headers.get(Constants.BUNDLE_SYMBOLICNAME); if (value == null) { return null; diff --git a/ui/org.eclipse.pde.ui/META-INF/MANIFEST.MF b/ui/org.eclipse.pde.ui/META-INF/MANIFEST.MF index 0747422568..3c9f14308e 100644 --- a/ui/org.eclipse.pde.ui/META-INF/MANIFEST.MF +++ b/ui/org.eclipse.pde.ui/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %name Bundle-SymbolicName: org.eclipse.pde.ui; singleton:=true -Bundle-Version: 3.14.0.qualifier +Bundle-Version: 3.14.100.qualifier Bundle-Activator: org.eclipse.pde.internal.ui.PDEPlugin Bundle-Vendor: %provider-name Bundle-Localization: plugin diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/ManifestEditor.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/ManifestEditor.java index 5cb3c9aaac..afe2298a11 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/ManifestEditor.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/ManifestEditor.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2021 IBM Corporation and others. + * Copyright (c) 2000, 2023 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -183,11 +183,12 @@ private static IEditorPart openWorkspacePlugin(IFile pluginFile) { private static IEditorPart openExternalPlugin(File location, String filename) { IEditorInput input = null; if (location.isFile()) { - try { - ZipFile zipFile = new ZipFile(location); - if (zipFile.getEntry(filename) != null) + try (ZipFile zipFile = new ZipFile(location)) { + if (zipFile.getEntry(filename) != null) { input = new JarEntryEditorInput(new JarEntryFile(zipFile, filename)); + } } catch (IOException e) { + // ignore } } else { File file = new File(location, filename);