@Test public void failing_rules_should_not_report_parse_exception() throws Exception { init(true); sensor.runCheck(context, new SonarXmlCheck() { @Override public void scanFile(XmlFile file) { throw new IllegalStateException("failing systematically"); } }, RuleKey.of("xml", "S666"), XmlFile.create(createInputFile("src/tabsEverywhere.xml"))); assertThat(context.allIssues()).isEmpty(); assertThat(logTester.getLogs()).isNotEmpty(); List<LogAndArguments> errors = logTester.getLogs(LoggerLevel.ERROR); assertThat(errors).hasSize(1); assertThat(errors.get(0).getRawMsg()).startsWith("Unable to execute rule xml:S666"); }
@VisibleForTesting void runCheck(SensorContext context, SonarXmlCheck check, RuleKey ruleKey, XmlFile newXmlFile) { try { check.scanFile(context, ruleKey, newXmlFile); } catch (Exception e) { logFailingRule(ruleKey, newXmlFile.getInputFile().uri(), e); } }
XmlSensor implements Sensor { @VisibleForTesting void runCheck(SensorContext context, SonarXmlCheck check, RuleKey ruleKey, XmlFile newXmlFile) { try { check.scanFile(context, ruleKey, newXmlFile); } catch (Exception e) { logFailingRule(ruleKey, newXmlFile.getInputFile().uri(), e); } } }
XmlSensor implements Sensor { @VisibleForTesting void runCheck(SensorContext context, SonarXmlCheck check, RuleKey ruleKey, XmlFile newXmlFile) { try { check.scanFile(context, ruleKey, newXmlFile); } catch (Exception e) { logFailingRule(ruleKey, newXmlFile.getInputFile().uri(), e); } } XmlSensor(FileSystem fileSystem, CheckFactory checkFactory, FileLinesContextFactory fileLinesContextFactory); }
XmlSensor implements Sensor { @VisibleForTesting void runCheck(SensorContext context, SonarXmlCheck check, RuleKey ruleKey, XmlFile newXmlFile) { try { check.scanFile(context, ruleKey, newXmlFile); } catch (Exception e) { logFailingRule(ruleKey, newXmlFile.getInputFile().uri(), e); } } XmlSensor(FileSystem fileSystem, CheckFactory checkFactory, FileLinesContextFactory fileLinesContextFactory); @Override void execute(SensorContext context); @Override String toString(); @Override void describe(SensorDescriptor descriptor); }
XmlSensor implements Sensor { @VisibleForTesting void runCheck(SensorContext context, SonarXmlCheck check, RuleKey ruleKey, XmlFile newXmlFile) { try { check.scanFile(context, ruleKey, newXmlFile); } catch (Exception e) { logFailingRule(ruleKey, newXmlFile.getInputFile().uri(), e); } } XmlSensor(FileSystem fileSystem, CheckFactory checkFactory, FileLinesContextFactory fileLinesContextFactory); @Override void execute(SensorContext context); @Override String toString(); @Override void describe(SensorDescriptor descriptor);  }