diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/plugin/JdbcDriverPluginDescriptorFinder.java b/backend/services/system-setting/src/main/java/io/metersphere/system/plugin/JdbcDriverPluginDescriptorFinder.java index 6173087a8b..36a5032d51 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/plugin/JdbcDriverPluginDescriptorFinder.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/plugin/JdbcDriverPluginDescriptorFinder.java @@ -44,9 +44,10 @@ public class JdbcDriverPluginDescriptorFinder extends ManifestPluginDescriptorFi if (jarEntry == null) { return false; } - InputStream inputStream = jar.getInputStream(jarEntry); - // 获取SPI中定义的类名 - driverClass = IOUtils.toString(inputStream); + try (InputStream inputStream = jar.getInputStream(jarEntry)) { + // 获取SPI中定义的类名 + driverClass = IOUtils.toString(inputStream); + } return true; } catch (IOException e) { throw new PluginRuntimeException(e, "Cannot read META-INF/services/java.sql.Driver from {}", jarPath); diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/PluginLoadService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/PluginLoadService.java index e07df19fa9..3257d2b9b9 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/PluginLoadService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/PluginLoadService.java @@ -122,10 +122,9 @@ public class PluginLoadService { public List getFrontendScripts(String pluginId) { MsPlugin msPluginInstance = (MsPlugin) msPluginManager.getPlugin(pluginId).getPlugin(); String scriptDir = msPluginInstance.getScriptDir(); - try { - List scripts = new ArrayList<>(10); - String jarPath = msPluginManager.getPlugin(pluginId).getPluginPath().toString(); - JarFile jarFile = new JarFile(jarPath); + List scripts = new ArrayList<>(10); + String jarPath = msPluginManager.getPlugin(pluginId).getPluginPath().toString(); + try (JarFile jarFile = new JarFile(jarPath)) { Enumeration entries = jarFile.entries(); while (entries.hasMoreElements()) { JarEntry jarEntry = entries.nextElement(); @@ -133,9 +132,10 @@ public class PluginLoadService { String innerPath = jarEntry.getName(); if (innerPath.startsWith(scriptDir) && !jarEntry.isDirectory()) { //获取到文件流 - InputStream inputStream = msPluginManager.getPluginClassLoader(pluginId).getResourceAsStream(innerPath); - if (inputStream != null) { - scripts.add(IOUtil.toString(inputStream)); + try (InputStream inputStream = msPluginManager.getPluginClassLoader(pluginId).getResourceAsStream(innerPath)) { + if (inputStream != null) { + scripts.add(IOUtil.toString(inputStream)); + } } } }