Fixed 'PackageInternalsFinder.fuse' throws an exception when jar in jar is empty (#2941)

This commit is contained in:
西东 2024-11-13 14:30:01 +08:00 committed by GitHub
parent 8200afb3cc
commit 6605b4abe3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -98,18 +98,22 @@ public class PackageInternalsFinder {
JarURLConnection jarConn = (JarURLConnection) packageFolderURL.openConnection(); JarURLConnection jarConn = (JarURLConnection) packageFolderURL.openConnection();
String rootEntryName = jarConn.getEntryName(); String rootEntryName = jarConn.getEntryName();
int rootEnd = rootEntryName.length() + 1;
Enumeration<JarEntry> entryEnum = jarConn.getJarFile().entries(); if (rootEntryName != null) {
while (entryEnum.hasMoreElements()) { //可能为 null自己没有类文件时
JarEntry jarEntry = entryEnum.nextElement(); int rootEnd = rootEntryName.length() + 1;
String name = jarEntry.getName();
if (name.startsWith(rootEntryName) && name.indexOf('/', rootEnd) == -1 && name.endsWith(CLASS_FILE_EXTENSION)) {
URI uri = URI.create(jarUri + "!/" + name);
String binaryName = name.replaceAll("/", ".");
binaryName = binaryName.replaceAll(CLASS_FILE_EXTENSION + "$", "");
result.add(new CustomJavaFileObject(binaryName, uri)); Enumeration<JarEntry> entryEnum = jarConn.getJarFile().entries();
while (entryEnum.hasMoreElements()) {
JarEntry jarEntry = entryEnum.nextElement();
String name = jarEntry.getName();
if (name.startsWith(rootEntryName) && name.indexOf('/', rootEnd) == -1 && name.endsWith(CLASS_FILE_EXTENSION)) {
URI uri = URI.create(jarUri + "!/" + name);
String binaryName = name.replaceAll("/", ".");
binaryName = binaryName.replaceAll(CLASS_FILE_EXTENSION + "$", "");
result.add(new CustomJavaFileObject(binaryName, uri));
}
} }
} }
} catch (Exception e) { } catch (Exception e) {