Skip to content

Commit

Permalink
Merge pull request #4749 from bergander:FixNoSuchMethodErrorInPmdCompat6
Browse files Browse the repository at this point in the history
Fixes NoSuchMethodError on processing errors in pmd-compat6 #4749
  • Loading branch information
adangel committed Dec 7, 2023
2 parents 0a63e74 + 071a632 commit abed5b0
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 2 deletions.
4 changes: 4 additions & 0 deletions docs/pages/release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ in the Migration Guide.
* [#4586](https://github.com/pmd/pmd/pull/4586): Use explicit encoding in ruleset xml files
* [#4642](https://github.com/pmd/pmd/issues/4642): Update regression tests with Java 21 language features
* [#4741](https://github.com/pmd/pmd/pull/4741): Add pmd-compat6 module for maven-pmd-plugin
* [#4749](https://github.com/pmd/pmd/pull/4749): Fixes NoSuchMethodError on processing errors in pmd-compat6
* apex-performance
* [#4675](https://github.com/pmd/pmd/issues/4675): \[apex] New Rule: OperationWithHighCostInLoop
* java
Expand Down Expand Up @@ -144,6 +145,7 @@ The following previously deprecated classes have been removed:
* [#4706](https://github.com/pmd/pmd/pull/4706): \[java] DetachedTestCase should not report on abstract methods - [Debamoy Datta](https://github.com/Debamoy) (@Debamoy)
* [#4719](https://github.com/pmd/pmd/pull/4719): \[java] UnnecessaryCaseChange: example doc toUpperCase() should compare to a capitalized string - [ciufudean](https://github.com/ciufudean) (@ciufudean)
* [#4738](https://github.com/pmd/pmd/pull/4738): \[doc] Added reference to the PMD extension for bld - [Erik C. Thauvin](https://github.com/ethauvin) (@ethauvin)
* [#4749](https://github.com/pmd/pmd/pull/4749): Fixes NoSuchMethodError on processing errors in pmd-compat6 - [Andreas Bergander](https://github.com/bergander) (@bergander)
* [#4750](https://github.com/pmd/pmd/pull/4750): \[core] Fix flaky SummaryHTMLRenderer - [219sansim](https://github.com/219sansim) (@219sansim)
* [#4754](https://github.com/pmd/pmd/pull/4754): \[java] EmptyControlStatementRule: Add allowCommentedBlocks property - [Andreas Bergander](https://github.com/bergander) (@bergander)
* [#4759](https://github.com/pmd/pmd/pull/4759): \[java] fix: remove delimiter attribute from ruleset category/java/errorprone.xml - [Marcin Dąbrowski](https://github.com/marcindabrowski) (@marcindabrowski)
Expand Down Expand Up @@ -497,6 +499,7 @@ See also [Detailed Release Notes for PMD 7]({{ baseurl }}pmd_release_notes_pmd7.
* [#4691](https://github.com/pmd/pmd/issues/4691): \[CVEs] Critical and High CEVs reported on PMD and PMD dependencies
* [#4699](https://github.com/pmd/pmd/pull/4699): Make PMD buildable with java 21
* [#4741](https://github.com/pmd/pmd/pull/4741): Add pmd-compat6 module for maven-pmd-plugin
* [#4749](https://github.com/pmd/pmd/pull/4749): Fixes NoSuchMethodError on processing errors in pmd-compat6
* ant
* [#4080](https://github.com/pmd/pmd/issues/4080): \[ant] Split off Ant integration into a new submodule
* core
Expand Down Expand Up @@ -811,6 +814,7 @@ Language specific fixes:
* [#4706](https://github.com/pmd/pmd/pull/4706): \[java] DetachedTestCase should not report on abstract methods - [Debamoy Datta](https://github.com/Debamoy) (@Debamoy)
* [#4719](https://github.com/pmd/pmd/pull/4719): \[java] UnnecessaryCaseChange: example doc toUpperCase() should compare to a capitalized string - [ciufudean](https://github.com/ciufudean) (@ciufudean)
* [#4738](https://github.com/pmd/pmd/pull/4738): \[doc] Added reference to the PMD extension for bld - [Erik C. Thauvin](https://github.com/ethauvin) (@ethauvin)
* [#4749](https://github.com/pmd/pmd/pull/4749): Fixes NoSuchMethodError on processing errors in pmd-compat6 - [Andreas Bergander](https://github.com/bergander) (@bergander)
* [#4750](https://github.com/pmd/pmd/pull/4750): \[core] Fix flaky SummaryHTMLRenderer - [219sansim](https://github.com/219sansim) (@219sansim)
* [#4754](https://github.com/pmd/pmd/pull/4754): \[java] EmptyControlStatementRule: Add allowCommentedBlocks property - [Andreas Bergander](https://github.com/bergander) (@bergander)
* [#4759](https://github.com/pmd/pmd/pull/4759): \[java] fix: remove delimiter attribute from ruleset category/java/errorprone.xml - [Marcin Dąbrowski](https://github.com/marcindabrowski) (@marcindabrowski)
Expand Down
16 changes: 16 additions & 0 deletions pmd-compat6/src/it/pmd-for-java/exception_ruleset.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<ruleset xmlns="http://pmd.sourceforge.net/ruleset/2.0.0" name="Exception throwing ruleset">
<description/>
<rule name="ExceptionThrowingRule"
language="java"
class="net.sourceforge.pmd.lang.rule.XPathRule">
<description>Use this rule to produce a processing error.</description>
<priority>3</priority>
<properties>
<property name="xpath">
<value><![CDATA[
error()
]]></value></property>
</properties>
</rule>
</ruleset>

6 changes: 5 additions & 1 deletion pmd-compat6/src/it/pmd-for-java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@
</executions>
<configuration>
<printFailingErrors>true</printFailingErrors>
<skipPmdError>false</skipPmdError>
<skipPmdError>true</skipPmdError> <!-- we want to capture processing errors -->
<minimumTokens>5</minimumTokens>
<rulesets>
<ruleset>/rulesets/java/maven-pmd-plugin-default.xml</ruleset>
<ruleset>${project.basedir}/exception_ruleset.xml</ruleset>
</rulesets>
</configuration>
<dependencies>
<dependency>
Expand Down
5 changes: 4 additions & 1 deletion pmd-compat6/src/it/pmd-for-java/verify.bsh
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@ String pmdXml = readFile(pmdXmlReport);
if (!pmdXml.contains("<violation beginline=\"5\" endline=\"5\" begincolumn=\"16\" endcolumn=\"37\" rule=\"UnusedLocalVariable\" ruleset=\"Best Practices\" package=\"org.example\" class=\"Main\" method=\"main\" variable=\"thisIsAUnusedLocalVar\"")) {
throw new RuntimeException("Expected violation has not been reported");
}
File mainFile = new File("pmd-for-java/src/main/java/org/example/Main.java");
File mainFile = new File(basedir, "src/main/java/org/example/Main.java");
if (!pmdXml.contains(mainFile + "\">")) {
throw new RuntimeException("Expected violation has not been reported");
}
if (!pmdXml.contains("<error filename=\"" + mainFile.getAbsolutePath()) || !pmdXml.contains(mainFile + "\" msg=\"PmdXPathException")) {
throw new RuntimeException("Processing error has not been reported");
}

File pmdCsvReport = new File(basedir, "target/pmd.csv");
if (!pmdCsvReport.exists()) {
Expand Down
5 changes: 5 additions & 0 deletions pmd-compat6/src/main/java/net/sourceforge/pmd/Report.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ public FileId getFileId() {
public Throwable getError() {
return error;
}

// ------------------- compat extensions --------------------
public String getFile() {
return file.getAbsolutePath();
}
}

/**
Expand Down

0 comments on commit abed5b0

Please sign in to comment.