From 6605b4abe3e837247656f741815eed7222a980f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A5=BF=E4=B8=9C?= Date: Wed, 13 Nov 2024 14:30:01 +0800 Subject: [PATCH] Fixed 'PackageInternalsFinder.fuse' throws an exception when jar in jar is empty (#2941) --- .../compiler/PackageInternalsFinder.java | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/memorycompiler/src/main/java/com/taobao/arthas/compiler/PackageInternalsFinder.java b/memorycompiler/src/main/java/com/taobao/arthas/compiler/PackageInternalsFinder.java index 471afc690..917c8cc92 100644 --- a/memorycompiler/src/main/java/com/taobao/arthas/compiler/PackageInternalsFinder.java +++ b/memorycompiler/src/main/java/com/taobao/arthas/compiler/PackageInternalsFinder.java @@ -98,18 +98,22 @@ public class PackageInternalsFinder { JarURLConnection jarConn = (JarURLConnection) packageFolderURL.openConnection(); String rootEntryName = jarConn.getEntryName(); - int rootEnd = rootEntryName.length() + 1; - Enumeration 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 + "$", ""); + if (rootEntryName != null) { + //可能为 null(自己没有类文件时) + int rootEnd = rootEntryName.length() + 1; - result.add(new CustomJavaFileObject(binaryName, uri)); + Enumeration 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) {