Skip to content

Commit 14dfaaa

Browse files
committed
Reconstruct directory entries when reading jar files
1 parent 1010fbf commit 14dfaaa

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

FernFlower-Patches/0050-Make-classpath-loading-lazy.patch

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,10 +1200,10 @@ index 0000000000000000000000000000000000000000..dbb6cc4d224fbb5ebbfc8156e8bea18e
12001200
+}
12011201
diff --git a/src/org/jetbrains/java/decompiler/struct/JarContextSource.java b/src/org/jetbrains/java/decompiler/struct/JarContextSource.java
12021202
new file mode 100644
1203-
index 0000000000000000000000000000000000000000..56127f683eca1fe1d28624eada88bf578c243e6e
1203+
index 0000000000000000000000000000000000000000..ef584a29055b12cec715039b9479e0d967114ae2
12041204
--- /dev/null
12051205
+++ b/src/org/jetbrains/java/decompiler/struct/JarContextSource.java
1206-
@@ -0,0 +1,135 @@
1206+
@@ -0,0 +1,148 @@
12071207
+// Copyright 2000-2022 JetBrains s.r.o. and ForgeFlower contributors Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
12081208
+package org.jetbrains.java.decompiler.struct;
12091209
+
@@ -1221,7 +1221,9 @@ index 0000000000000000000000000000000000000000..56127f683eca1fe1d28624eada88bf57
12211221
+import java.io.InputStream;
12221222
+import java.util.ArrayList;
12231223
+import java.util.Enumeration;
1224+
+import java.util.LinkedHashSet;
12241225
+import java.util.List;
1226+
+import java.util.Set;
12251227
+import java.util.jar.Manifest;
12261228
+import java.util.zip.ZipEntry;
12271229
+import java.util.zip.ZipFile;
@@ -1258,14 +1260,15 @@ index 0000000000000000000000000000000000000000..56127f683eca1fe1d28624eada88bf57
12581260
+ @Override
12591261
+ public Entries getEntries() {
12601262
+ final List<Entry> classes = new ArrayList<>();
1261-
+ final List<String> directories = new ArrayList<>();
1263+
+ final Set<String> directories = new LinkedHashSet<>();
12621264
+ final List<Entry> others = new ArrayList<>();
12631265
+
12641266
+ Enumeration<? extends ZipEntry> entries = this.file.entries();
12651267
+ while (entries.hasMoreElements()) {
12661268
+ ZipEntry entry = entries.nextElement();
12671269
+
12681270
+ String name = entry.getName();
1271+
+ addDirectories(entry, directories);
12691272
+ if (!entry.isDirectory()) {
12701273
+ if (name.endsWith(CLASS_SUFFIX)) {
12711274
+ classes.add(Entry.parse(name.substring(0, name.length() - CLASS_SUFFIX.length())));
@@ -1274,11 +1277,21 @@ index 0000000000000000000000000000000000000000..56127f683eca1fe1d28624eada88bf57
12741277
+ others.add(Entry.parse(name));
12751278
+ }
12761279
+ }
1277-
+ else {
1278-
+ directories.add(name);
1279-
+ }
12801280
+ }
1281-
+ return new Entries(classes, directories, others, List.of());
1281+
+ return new Entries(classes, List.copyOf(directories), others, List.of());
1282+
+ }
1283+
+
1284+
+ private void addDirectories(final ZipEntry entry, final Set<String> directories) {
1285+
+ final String name = entry.getName();
1286+
+ int segmentIndex = name.indexOf('/');
1287+
+ while (segmentIndex != -1) {
1288+
+ directories.add(name.substring(0, segmentIndex));
1289+
+ segmentIndex = name.indexOf('/', segmentIndex + 1);
1290+
+ }
1291+
+
1292+
+ if (entry.isDirectory()) {
1293+
+ directories.add(name);
1294+
+ }
12821295
+ }
12831296
+
12841297
+ @Override

0 commit comments

Comments
 (0)