From f89dcb77e93ec50173b4324d5cb121cb5d3fe8a5 Mon Sep 17 00:00:00 2001 From: Hannes Wellmann Date: Fri, 6 Sep 2024 21:21:07 +0200 Subject: [PATCH] Don't close a ZipEntryStorage archive file when obtaining its name Revert "Bug 558863 - Possible Recource leak warning in SourceElementQualifierProvider" This reverts commit 876dd122b731d57c8fe0da71298783891bc6c1f4. Fixes https://github.com/eclipse-platform/eclipse.platform.ui/issues/2251 --- org.eclipse.jdt.debug.ui/META-INF/MANIFEST.MF | 2 +- .../SourceElementQualifierProvider.java | 34 +++++++------------ 2 files changed, 13 insertions(+), 23 deletions(-) diff --git a/org.eclipse.jdt.debug.ui/META-INF/MANIFEST.MF b/org.eclipse.jdt.debug.ui/META-INF/MANIFEST.MF index 99fac8d243..611826bc52 100644 --- a/org.eclipse.jdt.debug.ui/META-INF/MANIFEST.MF +++ b/org.eclipse.jdt.debug.ui/META-INF/MANIFEST.MF @@ -50,7 +50,7 @@ Require-Bundle: org.eclipse.ui.ide;bundle-version="[3.5.0,4.0.0)", org.eclipse.search;bundle-version="[3.5.0,4.0.0)", org.eclipse.ui.forms;bundle-version="[3.4.0,4.0.0)", org.eclipse.core.resources, - org.eclipse.debug.core;bundle-version="[3.12.0,4.0.0)" + org.eclipse.debug.core;bundle-version="[3.22.0,4.0.0)" Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: JavaSE-17 Automatic-Module-Name: org.eclipse.jdt.debug.ui diff --git a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/launcher/SourceElementQualifierProvider.java b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/launcher/SourceElementQualifierProvider.java index 358f2159f6..17623149aa 100644 --- a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/launcher/SourceElementQualifierProvider.java +++ b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/launcher/SourceElementQualifierProvider.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2020 IBM Corporation and others. + * Copyright (c) 2000, 2024 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -15,12 +15,10 @@ import java.io.File; -import java.io.IOException; -import java.util.zip.ZipFile; +import java.nio.file.Path; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; import org.eclipse.debug.core.sourcelookup.containers.LocalFileStorage; import org.eclipse.debug.core.sourcelookup.containers.ZipEntryStorage; import org.eclipse.jdt.core.IJavaElement; @@ -49,25 +47,17 @@ public String getText(Object element) { if (element instanceof IJavaElement) { IJavaElement parent = ((IJavaElement)element).getParent(); return fJavaLabels.getText(parent); - } else if (element instanceof ZipEntryStorage) { - ZipEntryStorage storage = (ZipEntryStorage)element; - try (ZipFile archive = storage.getArchive()) { - String zipFileName = archive.getName(); - IPath path = new Path(zipFileName); - IRuntimeClasspathEntry entry = JavaRuntime.newArchiveRuntimeClasspathEntry(path); - IResource res = entry.getResource(); - if (res == null) { - // external - return zipFileName; - } - // internal - return res.getName(); - } catch (IOException e) { - e.printStackTrace(); + } else if (element instanceof ZipEntryStorage storage) { + Path zipFile = storage.getArchivePath(); + IPath path = IPath.fromPath(zipFile); + IRuntimeClasspathEntry entry = JavaRuntime.newArchiveRuntimeClasspathEntry(path); + IResource res = entry.getResource(); + if (res == null) { + // external + return zipFile.toString(); } - // ZipFile archive = storage.getArchive(); - // String zipFileName = archive.getName(); - + // internal + return res.getName(); } else if (element instanceof LocalFileStorage) { LocalFileStorage storage = (LocalFileStorage)element; File extFile = storage.getFile();