forked from phoedos/pmd
[core] XMLRenderer: ProcessingErrors from exceptions without a message missing
Fixes #1471 This also improves the message of the processing error by including the exception name.
This commit is contained in:
@ -30,6 +30,7 @@ This is a {{ site.pmd.release_type }} release.
|
||||
* [#1284](https://github.com/pmd/pmd/issues/1284): \[doc] Keep record of every currently deprecated API
|
||||
* [#1318](https://github.com/pmd/pmd/issues/1318): \[test] Kotlin DSL to ease test writing
|
||||
* [#1341](https://github.com/pmd/pmd/issues/1341): \[doc] Documentation Error with Regex Properties
|
||||
* [#1471](https://github.com/pmd/pmd/issues/1471): \[core] XMLRenderer: ProcessingErrors from exceptions without a message missing
|
||||
* java
|
||||
* [#1460](https://github.com/pmd/pmd/issues/1460): \[java] Intermittent PMD failure : PMD processing errors while no violations reported
|
||||
* java-codestyle
|
||||
|
@ -160,7 +160,7 @@ public class Report implements Iterable<RuleViolation> {
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return error.getMessage();
|
||||
return error.getClass().getSimpleName() + ": " + error.getMessage();
|
||||
}
|
||||
|
||||
public String getDetail() {
|
||||
|
@ -530,7 +530,7 @@ public class RuleSetTest {
|
||||
assertTrue("Report should have processing errors", context.getReport().hasErrors());
|
||||
List<ProcessingError> errors = CollectionUtil.toList(context.getReport().errors());
|
||||
assertEquals("Errors expected", 1, errors.size());
|
||||
assertEquals("Wrong error message", "Test exception while applying rule", errors.get(0).getMsg());
|
||||
assertEquals("Wrong error message", "RuntimeException: Test exception while applying rule", errors.get(0).getMsg());
|
||||
assertTrue("Should be a RuntimeException", errors.get(0).getError() instanceof RuntimeException);
|
||||
}
|
||||
|
||||
@ -577,7 +577,7 @@ public class RuleSetTest {
|
||||
assertTrue("Report should have processing errors", context.getReport().hasErrors());
|
||||
List<ProcessingError> errors = CollectionUtil.toList(context.getReport().errors());
|
||||
assertEquals("Errors expected", 1, errors.size());
|
||||
assertEquals("Wrong error message", "Test exception while applying rule", errors.get(0).getMsg());
|
||||
assertEquals("Wrong error message", "RuntimeException: Test exception while applying rule", errors.get(0).getMsg());
|
||||
assertTrue("Should be a RuntimeException", errors.get(0).getError() instanceof RuntimeException);
|
||||
|
||||
assertEquals("There should be a violation", 1, context.getReport().size());
|
||||
@ -617,7 +617,7 @@ public class RuleSetTest {
|
||||
assertTrue("Report should have processing errors", context.getReport().hasErrors());
|
||||
List<ProcessingError> errors = CollectionUtil.toList(context.getReport().errors());
|
||||
assertEquals("Errors expected", 1, errors.size());
|
||||
assertEquals("Wrong error message", "Test exception while applying rule", errors.get(0).getMsg());
|
||||
assertEquals("Wrong error message", "RuntimeException: Test exception while applying rule", errors.get(0).getMsg());
|
||||
assertTrue("Should be a RuntimeException", errors.get(0).getError() instanceof RuntimeException);
|
||||
|
||||
assertEquals("There should be a violation", 1, context.getReport().size());
|
||||
|
@ -38,6 +38,10 @@ public abstract class AbstractRendererTst {
|
||||
return "";
|
||||
}
|
||||
|
||||
public String getExpectedErrorWithoutMessage(ProcessingError error) {
|
||||
return getExpectedError(error);
|
||||
}
|
||||
|
||||
public String getExpectedError(ConfigurationError error) {
|
||||
return "";
|
||||
}
|
||||
@ -128,6 +132,15 @@ public abstract class AbstractRendererTst {
|
||||
assertEquals(filter(getExpectedError(err)), filter(actual));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testErrorWithoutMessage() throws Exception {
|
||||
Report rep = new Report();
|
||||
Report.ProcessingError err = new Report.ProcessingError(new NullPointerException(), "file");
|
||||
rep.addError(err);
|
||||
String actual = ReportTest.render(getRenderer(), rep);
|
||||
assertEquals(filter(getExpectedErrorWithoutMessage(err)), filter(actual));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConfigError() throws Exception {
|
||||
Report rep = new Report();
|
||||
|
@ -56,7 +56,14 @@ public class PapariTextRendererTest extends AbstractRendererTst {
|
||||
|
||||
@Override
|
||||
public String getExpectedError(ProcessingError error) {
|
||||
return PMD.EOL + PMD.EOL + "Summary:" + PMD.EOL + PMD.EOL + " err: Error" + PMD.EOL
|
||||
return PMD.EOL + PMD.EOL + "Summary:" + PMD.EOL + PMD.EOL + " err: RuntimeException: Error" + PMD.EOL
|
||||
+ error.getDetail() + PMD.EOL + PMD.EOL
|
||||
+ "* errors: 1" + PMD.EOL + "* warnings: 0" + PMD.EOL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getExpectedErrorWithoutMessage(ProcessingError error) {
|
||||
return PMD.EOL + PMD.EOL + "Summary:" + PMD.EOL + PMD.EOL + " err: NullPointerException: null" + PMD.EOL
|
||||
+ error.getDetail() + PMD.EOL + PMD.EOL
|
||||
+ "* errors: 1" + PMD.EOL + "* warnings: 0" + PMD.EOL;
|
||||
}
|
||||
|
@ -32,7 +32,12 @@ public class TextRendererTest extends AbstractRendererTst {
|
||||
|
||||
@Override
|
||||
public String getExpectedError(ProcessingError error) {
|
||||
return "file\t-\tError" + PMD.EOL;
|
||||
return "file\t-\tRuntimeException: Error" + PMD.EOL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getExpectedErrorWithoutMessage(ProcessingError error) {
|
||||
return "file\t-\tNullPointerException: null" + PMD.EOL;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -56,7 +56,13 @@ public class XMLRendererTest extends AbstractRendererTst {
|
||||
|
||||
@Override
|
||||
public String getExpectedError(ProcessingError error) {
|
||||
return getHeader() + "<error filename=\"file\" msg=\"Error\">"
|
||||
return getHeader() + "<error filename=\"file\" msg=\"RuntimeException: Error\">"
|
||||
+ PMD.EOL + "<![CDATA[" + error.getDetail() + "]]>" + PMD.EOL + "</error>" + PMD.EOL + "</pmd>" + PMD.EOL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getExpectedErrorWithoutMessage(ProcessingError error) {
|
||||
return getHeader() + "<error filename=\"file\" msg=\"NullPointerException: null\">"
|
||||
+ PMD.EOL + "<![CDATA[" + error.getDetail() + "]]>" + PMD.EOL + "</error>" + PMD.EOL + "</pmd>" + PMD.EOL;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user