diff --git a/debug/org.eclipse.debug.core/core/org/eclipse/debug/core/sourcelookup/containers/ZipEntryStorage.java b/debug/org.eclipse.debug.core/core/org/eclipse/debug/core/sourcelookup/containers/ZipEntryStorage.java index a4514c1d329..538c1d08072 100644 --- a/debug/org.eclipse.debug.core/core/org/eclipse/debug/core/sourcelookup/containers/ZipEntryStorage.java +++ b/debug/org.eclipse.debug.core/core/org/eclipse/debug/core/sourcelookup/containers/ZipEntryStorage.java @@ -16,6 +16,7 @@ import java.io.IOException; import java.io.InputStream; +import java.nio.file.Path; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; @@ -37,7 +38,6 @@ * @since 3.0 * @noextend This class is not intended to be subclassed by clients. */ -@SuppressWarnings("resource") public class ZipEntryStorage extends PlatformObject implements IStorage { /** @@ -65,7 +65,7 @@ public ZipEntryStorage(ZipFile archive, ZipEntry entry) { @Override public InputStream getContents() throws CoreException { try { - return getArchive().getInputStream(getZipEntry()); + return fArchive.getInputStream(getZipEntry()); } catch (IOException e) { throw new CoreException(new Status(IStatus.ERROR, DebugPlugin.getUniqueIdentifier(), DebugPlugin.ERROR, SourceLookupMessages.ZipEntryStorage_0, e)); } @@ -73,7 +73,7 @@ public InputStream getContents() throws CoreException { @Override public IPath getFullPath() { - return IPath.fromOSString(getArchive().getName()).append(getZipEntry().getName()); + return IPath.fromOSString(fArchive.getName()).append(getZipEntry().getName()); } @Override @@ -106,11 +106,27 @@ private void setArchive(ZipFile archive) { * Returns the archive containing the zip entry. * * @return zip file + * @deprecated Granting free access to the backing zip file archive is + * dangerous because a caller could close it prematurely and + * thus break all subsequent usages. Existing callers should use + * derived methods like {@link #getArchivePath()} or + * {@link #getContents()} instead, if possible. */ + @Deprecated public ZipFile getArchive() { return fArchive; } + /** + * Returns the path of the archive containing the zip entry in the + * file-system. + * + * @return the zip file's file-system path + */ + public Path getArchivePath() { + return Path.of(fArchive.getName()); + } + /** * Sets the entry that contains the source. * @@ -131,9 +147,9 @@ public ZipEntry getZipEntry() { @Override public boolean equals(Object object) { - return object instanceof ZipEntryStorage && - getArchive().equals(((ZipEntryStorage)object).getArchive()) && - getZipEntry().getName().equals(((ZipEntryStorage)object).getZipEntry().getName()); + return object instanceof ZipEntryStorage other // + && fArchive.equals(other.fArchive) // + && getZipEntry().getName().equals(other.getZipEntry().getName()); } @Override diff --git a/debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/sourcelookup/SourceElementWorkbenchAdapter.java b/debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/sourcelookup/SourceElementWorkbenchAdapter.java index 8acda22959e..b80292a17a1 100644 --- a/debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/sourcelookup/SourceElementWorkbenchAdapter.java +++ b/debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/sourcelookup/SourceElementWorkbenchAdapter.java @@ -41,7 +41,7 @@ public ImageDescriptor getImageDescriptor(Object o) { } return null; } - @SuppressWarnings("resource") + @Override public String getLabel(Object o) { if (o instanceof LocalFileStorage) { @@ -54,7 +54,7 @@ public String getLabel(Object o) { StringBuilder buffer = new StringBuilder(); buffer.append(storage.getZipEntry().getName()); buffer.append(" - "); //$NON-NLS-1$ - buffer.append(storage.getArchive().getName()); + buffer.append(storage.getArchivePath()); return buffer.toString(); } return IInternalDebugCoreConstants.EMPTY_STRING;