fix(parser): JsScriptLoader JarFile 改用 try-with-resources 防止文件句柄泄漏

JarFile 在手动 close() 时若中间抛异常会导致文件句柄未关闭,
改为 try-with-resources 确保无论正常或异常都能释放资源。
This commit is contained in:
yukaidi
2026-05-29 02:08:50 +08:00
parent 2f7304ab2d
commit bcc4315ea9

View File

@@ -139,8 +139,8 @@ public class JsScriptLoader {
try { try {
String jarPath = jarUrl.getPath().substring(5, jarUrl.getPath().indexOf("!")); String jarPath = jarUrl.getPath().substring(5, jarUrl.getPath().indexOf("!"));
JarFile jarFile = new JarFile(jarPath);
try (JarFile jarFile = new JarFile(jarPath)) {
Enumeration<JarEntry> entries = jarFile.entries(); Enumeration<JarEntry> entries = jarFile.entries();
while (entries.hasMoreElements()) { while (entries.hasMoreElements()) {
JarEntry entry = entries.nextElement(); JarEntry entry = entries.nextElement();
@@ -152,8 +152,7 @@ public class JsScriptLoader {
resourceFiles.add(entryName); resourceFiles.add(entryName);
} }
} }
}
jarFile.close();
} catch (Exception e) { } catch (Exception e) {
log.debug("解析JAR包资源文件失败", e); log.debug("解析JAR包资源文件失败", e);
} }