mirror of
https://github.com/qaiu/netdisk-fast-download.git
synced 2026-06-11 07:57:28 +00:00
fix(parser): JsScriptLoader JarFile 改用 try-with-resources 防止文件句柄泄漏
JarFile 在手动 close() 时若中间抛异常会导致文件句柄未关闭, 改为 try-with-resources 确保无论正常或异常都能释放资源。
This commit is contained in:
@@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user