diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index 939838888c..0ecc787131 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -23,6 +23,8 @@ This is a {{ site.pmd.release_type }} release. ### 🐛 Fixed Issues * cli * [#4791](https://github.com/pmd/pmd/issues/4791): \[cli] Could not find or load main class +* apex-errorprone + * [#3953](https://github.com/pmd/pmd/issues/3953): \[apex] EmptyCatchBlock false positive with formal (doc) comments * java-bestpractices * [#1084](https://github.com/pmd/pmd/issues/1084): \[java] Allow JUnitTestsShouldIncludeAssert to configure verification methods * [#4435](https://github.com/pmd/pmd/issues/4435): \[java] \[7.0-rc1] UnusedAssignment for used field diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexCommentBuilder.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexCommentBuilder.java index 2b9bf289a0..3d7f7445f7 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexCommentBuilder.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexCommentBuilder.java @@ -4,7 +4,6 @@ package net.sourceforge.pmd.lang.apex.ast; -import static java.util.stream.Collectors.toCollection; import static java.util.stream.Collectors.toList; import java.util.AbstractList; @@ -43,7 +42,7 @@ final class ApexCommentBuilder { TextRegion nodeRegion = commentContainer.getTextRegion(); // find the first comment after the start of the container node - int index = Collections.binarySearch(commentInfo.nonDocTokensByStartIndex, nodeRegion.getStartOffset()); + int index = Collections.binarySearch(commentInfo.allCommentsByStartIndex, nodeRegion.getStartOffset()); // no exact hit found - this is expected: there is no comment token starting at // the very same index as the node @@ -52,8 +51,8 @@ final class ApexCommentBuilder { index = ~index; // now check whether the next comment after the node is still inside the node - if (index >= 0 && index < commentInfo.nonDocTokensByStartIndex.size()) { - int commentStartIndex = commentInfo.nonDocTokensByStartIndex.get(index); + if (index >= 0 && index < commentInfo.allCommentsByStartIndex.size()) { + int commentStartIndex = commentInfo.allCommentsByStartIndex.get(index); return nodeRegion.getStartOffset() < commentStartIndex && nodeRegion.getEndOffset() >= commentStartIndex; } @@ -141,19 +140,16 @@ final class ApexCommentBuilder { private static class CommentInformation { final Map suppressMap; - final List nonDocTokensByStartIndex; + final List allCommentsByStartIndex; final List docTokens; CommentInformation(Map suppressMap, List allCommentTokens) { this.suppressMap = suppressMap; this.docTokens = allCommentTokens.stream() - .filter((token) -> token.getType() == ApexLexer.DOC_COMMENT) - .map((token) -> new ApexDocToken(token)) + .filter(token -> token.getType() == ApexLexer.DOC_COMMENT) + .map(ApexDocToken::new) .collect(toList()); - this.nonDocTokensByStartIndex = new TokenListByStartIndex( - allCommentTokens.stream() - .filter((token) -> token.getType() != ApexLexer.DOC_COMMENT) - .collect(toCollection(ArrayList::new))); + this.allCommentsByStartIndex = new TokenListByStartIndex(new ArrayList<>(allCommentTokens)); } } diff --git a/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/errorprone/xml/EmptyCatchBlock.xml b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/errorprone/xml/EmptyCatchBlock.xml index a850545cb1..03ae95ccf8 100644 --- a/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/errorprone/xml/EmptyCatchBlock.xml +++ b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/errorprone/xml/EmptyCatchBlock.xml @@ -297,27 +297,27 @@ private class FunctionalityTest { /////////////////////////////// try { } catch (Exception e) { - /** NOK: doc comment inside of empty catch block; should be reported */ + /** OK: doc comment inside of empty catch block; should be reported */ } try { } catch (Exception e) { - /** NOK: doc comment inside of empty catch block; + /** OK: doc comment inside of empty catch block; * multiple lines * should be reported */ } try { - } catch (Exception e) { /** NOK: doc comment inside of empty catch block, same line as begin; should be reported */ + } catch (Exception e) { /** OK: doc comment inside of empty catch block, same line as begin; should be reported */ } try { } catch (Exception e) { - /** NOK: doc comment inside of empty catch block, same line as end; should be reported */ } + /** OK: doc comment inside of empty catch block, same line as end; should be reported */ } try { - } catch (Exception e) { /** NOK: doc comment inside catch block, same line as begin/end; should be reported */ } + } catch (Exception e) { /** OK: doc comment inside catch block, same line as begin/end; should be reported */ } } } ]]> @@ -333,8 +333,8 @@ private class FunctionalityTest { #3569 - Verify use of allowCommentedBlocks=true, binary search boundaries verification true - 9 - 19,23,54,58,65,70,78,82,86 + 4 + 19,23,54,58