forked from phoedos/pmd
Fixed false positive when the first usage is an assignment to a field of the field (x.y = 5 instead of x = 5)
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@5561 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -427,9 +427,23 @@ Ok, field used to aggregate values
|
||||
public class Foo {
|
||||
private int x;
|
||||
int bar(int y) {
|
||||
x = x + y;
|
||||
x = x + y;
|
||||
return x;
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
<test-code>
|
||||
<description><![CDATA[
|
||||
Ok, setting values
|
||||
]]></description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
public class Foo {
|
||||
private Person p = new Person();
|
||||
public Foo(String name) {
|
||||
p.name = name;
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
@ -66,7 +66,8 @@ public class SingularField extends AbstractRule {
|
||||
|
||||
//Is the first usage in an assignment?
|
||||
Node potentialStatement = primaryExpressionParent.jjtGetParent();
|
||||
if (!isInAssignment(potentialStatement)) {
|
||||
boolean assignmentToField = no.getImage().equals(location.getImage()); //Check the the assignment is not to a field inside the field object
|
||||
if (!assignmentToField || !isInAssignment(potentialStatement)) {
|
||||
violation = false;
|
||||
break; //Optimization
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user