Skip to content

Commit

Permalink
Don't close a ZipEntryStorage archive file when obtaining its name
Browse files Browse the repository at this point in the history
Revert "Bug 558863 - Possible Recource leak warning in
SourceElementQualifierProvider"

This reverts commit 876dd12.

Fixes eclipse-platform/eclipse.platform.ui#2251
  • Loading branch information
HannesWell committed Sep 6, 2024
1 parent 5361162 commit e69fb5d
Showing 1 changed file with 12 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -15,12 +15,9 @@


import java.io.File;
import java.io.IOException;
import java.util.zip.ZipFile;

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;
Expand Down Expand Up @@ -49,25 +46,18 @@ 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) {
@SuppressWarnings("resource") // Don't close the archive to not break subsequent usages
String zipFileName = storage.getArchive().getName();
IPath path = IPath.fromOSString(zipFileName);
IRuntimeClasspathEntry entry = JavaRuntime.newArchiveRuntimeClasspathEntry(path);
IResource res = entry.getResource();
if (res == null) {
// external
return zipFileName;
}
// 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();
Expand Down

0 comments on commit e69fb5d

Please sign in to comment.