From 2c3001d2a748ca76db025ce90295011d0adecf77 Mon Sep 17 00:00:00 2001 From: yogiwaran2003 Date: Sat, 28 Feb 2026 10:28:47 +0530 Subject: [PATCH 1/2] fix: replace StringBuffer with StringBuilder and fix resource leaks in ConfigUtils --- .../dubbo/common/utils/ConfigUtils.java | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) 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 8c12944ef382..7d1856a152c0 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 @@ -139,7 +139,7 @@ public static String replaceProperty(String expression, Configuration configurat return expression; } Matcher matcher = VARIABLE_PATTERN.matcher(expression); - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); while (matcher.find()) { String key = matcher.group(1); String value = System.getProperty(key); @@ -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); + } } } } From bfe048fd989dea3afa6072ee140a752310526e1f Mon Sep 17 00:00:00 2001 From: yogiwaran2003 Date: Sat, 28 Feb 2026 10:45:54 +0530 Subject: [PATCH 2/2] fix: replace StringBuilder with StringBuffer and fix resource leaks in ConfigUtils --- .../main/java/org/apache/dubbo/common/utils/ConfigUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 7d1856a152c0..aad2ebaac96a 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 @@ -139,7 +139,7 @@ public static String replaceProperty(String expression, Configuration configurat return expression; } Matcher matcher = VARIABLE_PATTERN.matcher(expression); - StringBuilder sb = new StringBuilder(); + StringBuffer sb = new StringBuffer(); while (matcher.find()) { String key = matcher.group(1); String value = System.getProperty(key);