Skip to content

Commit 9e816b8

Browse files
authored
Merge pull request #1336 from DeHopen/fix_null_resource
Null Resource for Checkstyle Configuration
2 parents 55afed0 + e9a32c2 commit 9e816b8

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

qulice-checkstyle/src/main/java/com/qulice/checkstyle/CheckstyleValidator.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,17 +134,20 @@ private Configuration configuration() {
134134
}
135135
final Properties props = new Properties();
136136
props.setProperty("cache.file", cache.getPath());
137-
final InputSource src = new InputSource(
138-
this.getClass().getResourceAsStream("checks.xml")
139-
);
140137
final Configuration config;
141-
try {
138+
try (java.io.InputStream stream = this.getClass().getResourceAsStream("checks.xml")) {
139+
if (stream == null) {
140+
throw new IllegalStateException(
141+
"Checkstyle configuration file 'checks.xml' not found in classpath."
142+
);
143+
}
144+
final InputSource src = new InputSource(stream);
142145
config = ConfigurationLoader.loadConfiguration(
143146
src,
144147
new PropertiesExpander(props),
145148
ConfigurationLoader.IgnoredModulesOptions.OMIT
146149
);
147-
} catch (final CheckstyleException ex) {
150+
} catch (final CheckstyleException | java.io.IOException ex) {
148151
throw new IllegalStateException("Failed to load config", ex);
149152
}
150153
return config;

0 commit comments

Comments
 (0)