Skip to content

Commit b06ac9e

Browse files
Improvement: Prevent potential resource leak in CoreEvents.java (OFBIZ-13421) (#1241)
Improved: Prevent potential resource leak in CoreEvents.java (OFBIZ-13421) Refactor streamFile in CoreEvents.java to use try-with-resources. This prevents a potential file descriptor resource leak if the file streaming process throws an Exception.
1 parent b149bbe commit b06ac9e

1 file changed

Lines changed: 1 addition & 3 deletions

File tree

  • framework/webapp/src/main/java/org/apache/ofbiz/webapp/event

framework/webapp/src/main/java/org/apache/ofbiz/webapp/event/CoreEvents.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -516,10 +516,8 @@ public static String streamFile(HttpServletRequest request, HttpServletResponse
516516
if (file.exists()) {
517517
Long longLen = file.length();
518518
int length = longLen.intValue();
519-
try {
520-
FileInputStream fis = new FileInputStream(file);
519+
try (FileInputStream fis = new FileInputStream(file)) {
521520
UtilHttp.streamContentToBrowser(response, fis, length, null);
522-
fis.close();
523521
} catch (IOException e) {
524522
Debug.logError(e, MODULE);
525523
return "error";

0 commit comments

Comments
 (0)