Skip to content

Commit 82c3191

Browse files
authored
Replaced catching NPE with a null check (#625)
* checks that the InputStream is not null * remove printStackTrace()
1 parent 0d3ddb2 commit 82c3191

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

src/main/java/com/teragrep/pth_10/steps/teragrep/TeragrepSystemStep.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656

5757
import java.io.IOException;
5858
import java.io.InputStream;
59+
import java.io.UncheckedIOException;
5960
import java.net.UnknownHostException;
6061
import java.util.ArrayList;
6162
import java.util.List;
@@ -126,6 +127,9 @@ private List<String> getComponentVersions() {
126127
}
127128

128129
try (final InputStream is = TeragrepSystemStep.class.getClassLoader().getResourceAsStream("maven.properties")) {
130+
if (is == null) {
131+
throw new IllegalStateException("InputStream was Null, Problem fetching package properties");
132+
}
129133
final Properties p = new Properties();
130134
p.load(is);
131135
LOGGER.debug("package properties: <{}>", p);
@@ -140,8 +144,9 @@ private List<String> getComponentVersions() {
140144
}
141145
});
142146
}
143-
catch (IOException | NullPointerException e) {
144-
e.printStackTrace();
147+
catch (IOException e) {
148+
LOGGER.error("Failed to load InputStream: ", e);
149+
throw new UncheckedIOException("Failed to load InputStream: ", e);
145150
}
146151
return rv;
147152
}

0 commit comments

Comments
 (0)