From 86541071a31819999e8d7bdf163bbdd38246b997 Mon Sep 17 00:00:00 2001 From: Marcono1234 Date: Sat, 7 Sep 2024 22:09:59 +0200 Subject: [PATCH] Use try-with-resources --- .../com/google/gson/integration/OSGiManifestIT.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/gson/src/test/java/com/google/gson/integration/OSGiManifestIT.java b/gson/src/test/java/com/google/gson/integration/OSGiManifestIT.java index cf9d1f344a..4b3eea3256 100644 --- a/gson/src/test/java/com/google/gson/integration/OSGiManifestIT.java +++ b/gson/src/test/java/com/google/gson/integration/OSGiManifestIT.java @@ -160,11 +160,12 @@ private ManifestData findManifest(String bundleName) throws IOException { Collections.list(getClass().getClassLoader().getResources("META-INF/MANIFEST.MF")); for (URL manifestResource : manifestResources) { - InputStream is = manifestResource.openStream(); - Manifest mf = new Manifest(is); - is.close(); - if (bundleName.equals(mf.getMainAttributes().getValue("Bundle-SymbolicName"))) { - return new ManifestData(manifestResource, mf); + Manifest manifest; + try (InputStream is = manifestResource.openStream()) { + manifest = new Manifest(is); + } + if (bundleName.equals(manifest.getMainAttributes().getValue("Bundle-SymbolicName"))) { + return new ManifestData(manifestResource, manifest); } }