Affects PMD Version:
6.9.0
Rule:
codestyle/CommentDefaultAccessmodifier
Description:
When reporting on a constructor, the error message is:
To avoid mistakes add a comment at the beginning of the null constructor if you want a default access modifier
It shouldn't say null, but the name of the constructor:
To avoid mistakes add a comment at the beginning of the Foo constructor if you want a default access modifier
Code Sample demonstrating the issue:
public class Foo {
Foo() { }
}
Running PMD through: Any
Hi,
Can i take up this issue?
@keerthikorivi of course you can! All PRs are welcomed
Hi @jsotuyod,
I just wanted to confirm my understanding of the issue, the issue is that when we create a class say, Foo, as shown below with a default constructor and use pmd 6.9.0 in the build then it fails with the error message: To avoid mistakes add a comment at the beginning of the null constructor if you want a default access modifier
Instead, it should specify the class name instead of null
public class Foo {
Foo() { }
}
Please let me know if that's correct?
@keerthikorivi exactly.
@jsotuyod I ran the code locally and saw the value of decl.getImage() is null.
@Override
public Object visit(final ASTClassOrInterfaceDeclaration decl, final Object data) {
// check for nested classes
if (decl.isNested() && shouldReport(decl)) {
addViolationWithMessage(data, decl, String.format(MESSAGE, decl.getImage(), "nested class"));
}
return super.visit(decl, data);
}
Going through the code I was not able to figure out where does this get set actually. Can you please point me to that code snippet. This should help me debug further.
@keerthikorivi the problem lies within the grammar itself, not setting the image for the node to the <IDENTIFIER>:
You can see how this is done for other nodes such as:
Most helpful comment
Hi,
Can i take up this issue?