Skip to content

Commit 96d8211

Browse files
committed
Fix filehandle leak
1 parent 27cceba commit 96d8211

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/main/java/com/chainstaysoftware/filechooser/icons/IconsImpl.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.apache.commons.io.FilenameUtils;
88

99
import java.io.File;
10+
import java.io.IOException;
1011
import java.io.InputStream;
1112
import java.util.HashMap;
1213
import java.util.Locale;
@@ -105,12 +106,15 @@ public Image getIcon(final String resourceName) {
105106
throw new IllegalArgumentException("resourceName must not be null");
106107
}
107108

108-
final InputStream inputStream = IconsImpl.class.getResourceAsStream(resourceName);
109-
if (inputStream == null) {
110-
throw new IllegalArgumentException(resourceName + " is not a valid resource");
111-
}
109+
try (final InputStream inputStream = IconsImpl.class.getResourceAsStream(resourceName)) {
110+
if (inputStream == null) {
111+
throw new IllegalArgumentException(resourceName + " is not a valid resource");
112+
}
112113

113-
return new Image(inputStream);
114+
return new Image(inputStream);
115+
} catch (IOException e) {
116+
throw new IllegalArgumentException(resourceName + " is not a valid resource", e);
117+
}
114118
}
115119

116120
/**

0 commit comments

Comments
 (0)