You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description:
Violations of rule CommentSize are not suppressed by the annotations @SuppressWarnings("PMD.CommentSize") or @SuppressWarnings("PMD") when placed on the method definition.
Code Sample demonstrating the issue:
packagepmdtests;
publicfinalclassTestComment {
@SuppressWarnings("PMD.CommentSize")
privateTestComment() {
/* * Writing and maintaining complicated software is a difficult task, * and every programmer inadvertently makes mistakes. * Usually these are minor typographical errors that will be caught at * compile time, but others may remain undetected until the system is in production. * In the most extreme cases, the bug will cause system failure, as was the case in * the massive blackout in the Northeast last summer. * In addition to the consequences of system malfunction, * software defects have a substantial financial cost. * A 2003 report from the National Institute of Standards and Technology (NIST) * calculated the total annual cost of bugs at nearly $60 billion. * The report also confirmed what most developers already know: * the difficulty and cost of fixing a problem grows dramatically throughout the development cycle. * Although the report concluded that it is not practical to locate and remove all defects * from an application, it stated that nearly 40% could be eliminated by an improved inspection and testing * process. * * Two common methods for improving software quality are code reviews and automated * testing. The goal of both is to detect mistakes, but the distinction between them * is how this is achieved. Automated testing attempts to expose problems by executing * the code, while reviews rely on "another set of eyes" to verify that it's correct. * Problems can arise when we get too involved with the code to be objective or to consider * unusual paths of execution. Certainly every programmer has at one time * spent hours trying to track down a problem only to have someone else spot it * immediately. */thrownewUnsupportedOperationException(
"This is a utility class and cannot be instantiated");
}
publicstaticvoidmain(String... args) {
// empty main
}
}
@oowekyala Hi, oowekyala, I think this issue is very interesting and find you have added this to 7.0 milestone, could you please tell me the root cause or spot the potental buggy code file? THX.
Rules normally report violations on an AST node that corresponds to the location of the violation, and that node is used to find an enclosing annotation, by inspecting its ancestors until the root of the tree. The problem is that comments are not nodes in the AST, and we also have no API to find a node close to a comment (although that exists in the designer currently). So this rule always uses the root node as a placeholder, eg here https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/documentation/CommentSizeRule.java#L105
I marked this for PMD 7 because maybe we can have a nicer solution then, eg by representing comments as actual nodes in the tree. There is a todo item in #3898 about that. Also moving the linked designer code into pmd-core would be easier in PMD 7 as there are already data types there to represent text positions, which in PMD 6 only exist in the designer codebase (this TextPos2d class).
Affects PMD Version:
6.30.0
Description:
Violations of rule CommentSize are not suppressed by the annotations @SuppressWarnings("PMD.CommentSize") or @SuppressWarnings("PMD") when placed on the method definition.
Code Sample demonstrating the issue:
Running PMD through: [CLI | Ant | Maven | Gradle | Designer | Other]
Referred from: #2995
The text was updated successfully, but these errors were encountered: