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
Situation: a class whose elements are properly instantiated with a no-argument constructor.
If the code is left without a constructor, the compiler will provide one, but PMD complains: Each class should have at least one constructor
If a constructor is provided in the code, PMD complains: Avoid unnecessary constructors - the compiler will generate these for you
Sure, the programmer can insert @SuppressWarnings into (otherwise very simple) code,
but this really shouldn't be necessary. Sure, the programmer can disable either warning globally...
but in fact, both warnings are good to have.
But as it is, it leaves the programmer thinking: "Make up your mind!". And it wastes time.
I'm not sure what measure would be best to take.
Perhaps a property for the UnnecessaryConstructor rule,
"allowSingleConstructor", or something like that, would help.
Exception Stacktrace:
# Copy-paste the stack trace here
Code Sample demonstrating the issue:
/** An overly-simple example */classExampleClass {
// If this constructor is present, PMD complains.// If this constructor is removed, PMD complains.ExampleClass(){
}
}
The situation arises in many practical cases. For instance, the documentation for javax.annotation.processing.Processor
explicitly states
"Each implementation of a Processor must provide a public no-argument constructor to be used by tools to instantiate the processor."
Steps to reproduce:
Please provide detailed steps for how we can reproduce the bug.
... Run PMD on a file named ExampleClass.java containing the above code
Affects PMD Version:
7.0.0
Description:
Situation: a class whose elements are properly instantiated with a no-argument constructor.
If the code is left without a constructor, the compiler will provide one, but PMD complains:
Each class should have at least one constructor
If a constructor is provided in the code, PMD complains:
Avoid unnecessary constructors - the compiler will generate these for you
Sure, the programmer can insert
@SuppressWarnings
into (otherwise very simple) code,but this really shouldn't be necessary. Sure, the programmer can disable either warning globally...
but in fact, both warnings are good to have.
But as it is, it leaves the programmer thinking: "Make up your mind!". And it wastes time.
I'm not sure what measure would be best to take.
Perhaps a property for the UnnecessaryConstructor rule,
"allowSingleConstructor", or something like that, would help.
Exception Stacktrace:
Code Sample demonstrating the issue:
The situation arises in many practical cases. For instance, the documentation for
javax.annotation.processing.Processor
explicitly states
"Each implementation of a Processor must provide a public no-argument constructor to be used by tools to instantiate the processor."
Steps to reproduce:
Please provide detailed steps for how we can reproduce the bug.
Running PMD through: [CLI | Ant | Maven | Gradle | Designer | Other]
Running PMD through CLI
The text was updated successfully, but these errors were encountered: