From ef2ce2fa9a9fd20286264a889b1dd793cb704459 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0=D0=BD=D0=B4=D1=8A?= =?UTF-8?q?=D1=80=20=D0=9A=D1=83=D1=80=D1=82=D0=B0=D0=BA=D0=BE=D0=B2?= Date: Wed, 17 Apr 2024 10:24:55 +0300 Subject: [PATCH] Suppress try-with-resources warning Jars are stored in a list and closed altogether at the end. Fixes https://download.eclipse.org/eclipse/downloads/drops4/I20240416-1800/compilelogs/plugins/org.eclipse.equinox.p2.discovery.compatibility_1.3.300.v20240321-1450/@dot.html#OTHER_WARNINGS --- .../DiscoveryRegistryStrategy.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/bundles/org.eclipse.equinox.p2.discovery.compatibility/src/org/eclipse/equinox/internal/p2/discovery/compatibility/DiscoveryRegistryStrategy.java b/bundles/org.eclipse.equinox.p2.discovery.compatibility/src/org/eclipse/equinox/internal/p2/discovery/compatibility/DiscoveryRegistryStrategy.java index c904f99e26..97b6aed7a2 100644 --- a/bundles/org.eclipse.equinox.p2.discovery.compatibility/src/org/eclipse/equinox/internal/p2/discovery/compatibility/DiscoveryRegistryStrategy.java +++ b/bundles/org.eclipse.equinox.p2.discovery.compatibility/src/org/eclipse/equinox/internal/p2/discovery/compatibility/DiscoveryRegistryStrategy.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2017 Tasktop Technologies and others. + * Copyright (c) 2009, 2024 Tasktop Technologies and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -59,7 +59,8 @@ private void processDiscoveryCoreBundle(IExtensionRegistry registry) { // extension point itself try { Bundle bundle = Platform.getBundle("org.eclipse.equinox.p2.discovery.compatibility"); //$NON-NLS-1$ - IContributor contributor = new RegistryContributor(bundle.getSymbolicName(), bundle.getSymbolicName(), null, null); + IContributor contributor = new RegistryContributor(bundle.getSymbolicName(), bundle.getSymbolicName(), null, + null); try (InputStream inputStream = bundle.getEntry("plugin.xml").openStream()) { //$NON-NLS-1$ registry.addContribution(inputStream, contributor, false, bundle.getSymbolicName(), null, token); @@ -77,12 +78,16 @@ private void processBundles(IExtensionRegistry registry) { try { processBundle(registry, bundleFile.getValue(), bundleFile.getKey()); } catch (Exception e) { - LogHelper.log(new Status(IStatus.ERROR, DiscoveryCore.ID_PLUGIN, NLS.bind(Messages.DiscoveryRegistryStrategy_cannot_load_bundle, new Object[] {bundleFile.getKey().getName(), bundleFile.getValue().getLocation(), e.getMessage()}), e)); + LogHelper.log(new Status(IStatus.ERROR, DiscoveryCore.ID_PLUGIN, + NLS.bind(Messages.DiscoveryRegistryStrategy_cannot_load_bundle, new Object[] { + bundleFile.getKey().getName(), bundleFile.getValue().getLocation(), e.getMessage() }), + e)); } } } private void processBundle(IExtensionRegistry registry, Directory.Entry entry, File bundleFile) throws IOException { + @SuppressWarnings("resource") JarFile jarFile = new JarFile(bundleFile); jars.add(jarFile); @@ -159,8 +164,7 @@ public void onStop(IExtensionRegistry registry) { /** * get the jar file that corresponds to the given contributor. * - * @throws IllegalArgumentException - * if the given contributor is unknown + * @throws IllegalArgumentException if the given contributor is unknown */ public File getJarFile(IContributor contributor) { File file = contributorToJarFile.get(contributor); @@ -173,8 +177,7 @@ public File getJarFile(IContributor contributor) { /** * get the directory entry that corresponds to the given contributor. * - * @throws IllegalArgumentException - * if the given contributor is unknown + * @throws IllegalArgumentException if the given contributor is unknown */ public Entry getDirectoryEntry(IContributor contributor) { Entry entry = contributorToDirectoryEntry.get(contributor);