Skip to content

Commit

Permalink
Fix filehandle leak
Browse files Browse the repository at this point in the history
  • Loading branch information
ricemery committed May 2, 2017
1 parent 27cceba commit 96d8211
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.apache.commons.io.FilenameUtils;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Locale;
Expand Down Expand Up @@ -105,12 +106,15 @@ public Image getIcon(final String resourceName) {
throw new IllegalArgumentException("resourceName must not be null");
}

final InputStream inputStream = IconsImpl.class.getResourceAsStream(resourceName);
if (inputStream == null) {
throw new IllegalArgumentException(resourceName + " is not a valid resource");
}
try (final InputStream inputStream = IconsImpl.class.getResourceAsStream(resourceName)) {
if (inputStream == null) {
throw new IllegalArgumentException(resourceName + " is not a valid resource");
}

return new Image(inputStream);
return new Image(inputStream);
} catch (IOException e) {
throw new IllegalArgumentException(resourceName + " is not a valid resource", e);
}
}

/**
Expand Down

0 comments on commit 96d8211

Please sign in to comment.