Issue #1566: IllegalCatch violations fixed for Checker

This commit is contained in:
Ruslan Diachenko 2015-08-30 21:44:29 +01:00 committed by Roman Ivanov
parent 83b0e16b0a
commit d740f2e1cd
2 changed files with 23 additions and 21 deletions

View File

@ -152,35 +152,38 @@ public class Checker extends AutomaticBean implements MessageDispatcher {
protected void setupChild(Configuration childConf)
throws CheckstyleException {
final String name = childConf.getName();
final Object child;
try {
final Object child = moduleFactory.createModule(name);
child = moduleFactory.createModule(name);
if (child instanceof AutomaticBean) {
final AutomaticBean bean = (AutomaticBean) child;
bean.contextualize(childContext);
bean.configure(childConf);
}
if (child instanceof FileSetCheck) {
final FileSetCheck fsc = (FileSetCheck) child;
fsc.init();
addFileSetCheck(fsc);
}
else if (child instanceof Filter) {
final Filter filter = (Filter) child;
addFilter(filter);
}
else if (child instanceof AuditListener) {
final AuditListener listener = (AuditListener) child;
addListener(listener);
}
else {
throw new CheckstyleException(name
+ " is not allowed as a child in Checker");
}
}
catch (final Exception ex) {
catch (final CheckstyleException ex) {
throw new CheckstyleException("cannot initialize module " + name
+ " - " + ex.getMessage(), ex);
}
if (child instanceof FileSetCheck) {
final FileSetCheck fsc = (FileSetCheck) child;
fsc.init();
addFileSetCheck(fsc);
}
else if (child instanceof Filter) {
final Filter filter = (Filter) child;
addFilter(filter);
}
else if (child instanceof AuditListener) {
final AuditListener listener = (AuditListener) child;
addListener(listener);
}
else {
throw new CheckstyleException(name
+ " is not allowed as a child in Checker");
}
}
/**

View File

@ -256,8 +256,7 @@ public class CheckerTest {
fail("Exception is expected");
}
catch (CheckstyleException ex) {
assertEquals("cannot initialize module java.lang.String "
+ "- java.lang.String is not allowed as a child in Checker", ex.getMessage());
assertEquals("java.lang.String is not allowed as a child in Checker", ex.getMessage());
}
}