diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/ConfigUtils.java b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/ConfigUtils.java index 8c12944ef38..aad2ebaac96 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/ConfigUtils.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/ConfigUtils.java @@ -281,16 +281,10 @@ public static Properties loadProperties( for (java.net.URL url : set) { try { Properties p = new Properties(); - InputStream input = url.openStream(); - if (input != null) { - try { + try (InputStream input = url.openStream()) { + if (input != null) { p.load(input); properties.putAll(p); - } finally { - try { - input.close(); - } catch (Throwable t) { - } } } } catch (Throwable e) { @@ -331,9 +325,10 @@ public static String loadMigrationRule(Set classLoaders, String fil for (Set urls : ClassLoaderResourceLoader.loadResources(fileName, classLoadersToLoad) .values()) { for (URL url : urls) { - InputStream is = url.openStream(); - if (is != null) { - return readString(is); + try (InputStream is = url.openStream()) { + if (is != null) { + return readString(is); + } } } }