-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[java] SingularField ignores static variables #3694
Comments
This comment was marked as outdated.
This comment was marked as outdated.
Actually, this is not fixed yet. The following test case still doesn't report any violations: <test-code>
<description>[java] Make SingularField can detect modified variables #3694</description>
<expected-problems>2</expected-problems>
<expected-linenumbers>2,3</expected-linenumbers>
<code><![CDATA[
class Impl {
final private final int var1 = 10; // should report a warning here
static private int var2 = 10; // also should report a warning here
public int foo() {
return var1;
}
public int foo(int y) {
var2 = y + 5;
return var2;
}
}
]]></code>
</test-code> |
The rule doesn't check static or final fields by design, although that could probably be relaxed. The issue is probably misnamed. |
oowekyala
added a commit
to oowekyala/pmd
that referenced
this issue
May 3, 2023
4 tasks
oowekyala
changed the title
[java] Make SingularField can detect modified variables
[java] SingularField ignores static variables
May 3, 2023
4 tasks
jsotuyod
added
the
needs:pmd7-revalidation
The issue hasn't yet been retested vs PMD 7 and may be stale
label
Mar 17, 2024
jsotuyod
removed
the
needs:pmd7-revalidation
The issue hasn't yet been retested vs PMD 7 and may be stale
label
Mar 26, 2024
adangel
added a commit
that referenced
this issue
Apr 3, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Affects PMD Version:
6.41.0+
7.0.0
Rule:SingularField
Please provide the rule name and a link to the rule documentation:
https://pmd.github.io/latest/pmd_rules_java_design.html#singularfield
Description:
Hi, I found two false negatives about the rule SingularField. Please refer to the following case, PMD should have reported a false negative at line 2 and 3. I think these cases are caused by modifiers of
var1
andvar2
.Code Sample demonstrating the issue:
Expected outcome:
PMD should report violations at line 2 and 3, but doesn't. This is a false-negative.
Running PMD through: [Maven]
The text was updated successfully, but these errors were encountered: