Skip to content

Commit 75d509d

Browse files
committed
Add ZipEntryStorage.getArchivePath() and deprecate its getArchive()
This helps to prevent issues like eclipse-platform/eclipse.platform.ui#2251
1 parent 846a9ad commit 75d509d

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

debug/org.eclipse.debug.core/core/org/eclipse/debug/core/sourcelookup/containers/ZipEntryStorage.java

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import java.io.IOException;
1818
import java.io.InputStream;
19+
import java.nio.file.Path;
1920
import java.util.zip.ZipEntry;
2021
import java.util.zip.ZipFile;
2122

@@ -37,7 +38,6 @@
3738
* @since 3.0
3839
* @noextend This class is not intended to be subclassed by clients.
3940
*/
40-
@SuppressWarnings("resource")
4141
public class ZipEntryStorage extends PlatformObject implements IStorage {
4242

4343
/**
@@ -65,15 +65,15 @@ public ZipEntryStorage(ZipFile archive, ZipEntry entry) {
6565
@Override
6666
public InputStream getContents() throws CoreException {
6767
try {
68-
return getArchive().getInputStream(getZipEntry());
68+
return fArchive.getInputStream(getZipEntry());
6969
} catch (IOException e) {
7070
throw new CoreException(new Status(IStatus.ERROR, DebugPlugin.getUniqueIdentifier(), DebugPlugin.ERROR, SourceLookupMessages.ZipEntryStorage_0, e));
7171
}
7272
}
7373

7474
@Override
7575
public IPath getFullPath() {
76-
return IPath.fromOSString(getArchive().getName()).append(getZipEntry().getName());
76+
return IPath.fromOSString(fArchive.getName()).append(getZipEntry().getName());
7777
}
7878

7979
@Override
@@ -106,11 +106,28 @@ private void setArchive(ZipFile archive) {
106106
* Returns the archive containing the zip entry.
107107
*
108108
* @return zip file
109+
* @deprecated Granting free access to the backing zip file archive is
110+
* dangerous because a caller could close it prematurely and
111+
* thus break all subsequent usages. Existing callers should use
112+
* derived methods like {@link #getArchivePath()} or
113+
* {@link #getContents()} instead, if possible.
109114
*/
115+
@Deprecated(forRemoval = true, since = "3.22 (removal in 2026-12 or later)")
110116
public ZipFile getArchive() {
111117
return fArchive;
112118
}
113119

120+
/**
121+
* Returns the path of the archive containing the zip entry in the
122+
* file-system.
123+
*
124+
* @return the zip file's file-system path
125+
* @since 3.22
126+
*/
127+
public Path getArchivePath() {
128+
return Path.of(fArchive.getName());
129+
}
130+
114131
/**
115132
* Sets the entry that contains the source.
116133
*
@@ -131,9 +148,9 @@ public ZipEntry getZipEntry() {
131148

132149
@Override
133150
public boolean equals(Object object) {
134-
return object instanceof ZipEntryStorage &&
135-
getArchive().equals(((ZipEntryStorage)object).getArchive()) &&
136-
getZipEntry().getName().equals(((ZipEntryStorage)object).getZipEntry().getName());
151+
return object instanceof ZipEntryStorage other //
152+
&& fArchive.equals(other.fArchive) //
153+
&& getZipEntry().getName().equals(other.getZipEntry().getName());
137154
}
138155

139156
@Override

debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/sourcelookup/SourceElementWorkbenchAdapter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public ImageDescriptor getImageDescriptor(Object o) {
4141
}
4242
return null;
4343
}
44-
@SuppressWarnings("resource")
44+
4545
@Override
4646
public String getLabel(Object o) {
4747
if (o instanceof LocalFileStorage) {
@@ -54,7 +54,7 @@ public String getLabel(Object o) {
5454
StringBuilder buffer = new StringBuilder();
5555
buffer.append(storage.getZipEntry().getName());
5656
buffer.append(" - "); //$NON-NLS-1$
57-
buffer.append(storage.getArchive().getName());
57+
buffer.append(storage.getArchivePath());
5858
return buffer.toString();
5959
}
6060
return IInternalDebugCoreConstants.EMPTY_STRING;

0 commit comments

Comments
 (0)