Skip to content

Commit 78946bf

Browse files
committed
fix: close URL stream via try-with-resources in ExtensionUtil
in.close() not in finally; exception during readLine() leaks the underlying HTTP connection; use try-with-resources to guarantee closure on all paths Signed-off-by: Nico Piel <nico.piel@hotmail.de>
1 parent 4200949 commit 78946bf

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

client/src/com/mirth/connect/client/ui/extensionmanager/ExtensionUtil.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,14 @@ public String getURLContents(String address) {
3434

3535
try {
3636
URL url = new URL(address);
37-
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
38-
String str = null;
37+
try (BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()))) {
38+
String str;
3939

40-
while ((str = in.readLine()) != null) {
41-
builder.append(str);
42-
builder.append("\r\n");
40+
while ((str = in.readLine()) != null) {
41+
builder.append(str);
42+
builder.append("\r\n");
43+
}
4344
}
44-
45-
in.close();
4645
} catch (Exception e) {
4746
// could not load page contents
4847
}

0 commit comments

Comments
 (0)