Issue #3771: fixed in NPE in cache for HeaderCheck
This commit is contained in:
parent
861612671a
commit
4cff2eb714
|
|
@ -193,6 +193,15 @@ public abstract class AbstractHeaderCheck extends AbstractFileSetCheck
|
|||
|
||||
@Override
|
||||
public Set<String> getExternalResourceLocations() {
|
||||
return Collections.singleton(headerFile.toString());
|
||||
final Set<String> result;
|
||||
|
||||
if (headerFile == null) {
|
||||
result = Collections.emptySet();
|
||||
}
|
||||
else {
|
||||
result = Collections.singleton(headerFile.toString());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -268,4 +268,25 @@ public class HeaderCheckTest extends BaseFileSetCheckTestSupport {
|
|||
verify(checker, getPath("InputHeader.java"), expected);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCacheHeaderWithoutFile() throws Exception {
|
||||
final DefaultConfiguration checkConfig = createCheckConfig(HeaderCheck.class);
|
||||
checkConfig.addAttribute("header", "Test");
|
||||
|
||||
final DefaultConfiguration checkerConfig = new DefaultConfiguration("checkstyle_checks");
|
||||
checkerConfig.addChild(checkConfig);
|
||||
checkerConfig.addAttribute("cacheFile", temporaryFolder.newFile().getPath());
|
||||
|
||||
final Checker checker = new Checker();
|
||||
checker.setModuleClassLoader(Thread.currentThread().getContextClassLoader());
|
||||
checker.configure(checkerConfig);
|
||||
checker.addListener(new BriefUtLogger(stream));
|
||||
|
||||
final String[] expected = {
|
||||
"1: " + getCheckMessage(MSG_MISMATCH, "Test"),
|
||||
};
|
||||
|
||||
verify(checker, getPath("InputHeader.java"), expected);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue