Skip to content

Commit

Permalink
pmd: fixed bug #3526212 with immutable field and compound assignment
Browse files Browse the repository at this point in the history
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@7683 51baf565-9d33-0410-a72c-fc3788e3496d
  • Loading branch information
adangel committed Jun 2, 2012
1 parent 196a5f1 commit eb6c0c8
Showing 3 changed files with 39 additions and 7 deletions.
1 change: 1 addition & 0 deletions pmd/etc/changelog.txt
Original file line number Diff line number Diff line change
@@ -27,6 +27,7 @@ TODO - Release blockers - Must implement before this release can be finally fini
and pmd-java:typeof).


Fixed bug 3526212: pmd-5.0.0: ImmutableField false positive on self-inc/dec
Fixed bug 3526992: pmd-5.0.0: False + UselessParentheses
Fixed bug 3523614: newline characters stripped from CPD data in PMD 5.0.0
Fixed bug 3516101: InsufficientStringBufferDeclaration fails to parse hex
Original file line number Diff line number Diff line change
@@ -148,13 +148,12 @@ public boolean isSelfAssignment() {
return true;
}

if (node instanceof ASTStatementExpression || node instanceof ASTExpression) {
if (node.jjtGetNumChildren() >= 2 && node.jjtGetChild(1) instanceof ASTAssignmentOperator) {
ASTAssignmentOperator op = (ASTAssignmentOperator) node.jjtGetChild(1);
if (op.isCompound()) {
return true;
}
}
if (hasAssignmentOperator(gp)) {
return isCompoundAssignment(gp);
}

if (hasAssignmentOperator(node)) {
return isCompoundAssignment(node);
}

// deal with extra parenthesis: "(i)++"
@@ -171,6 +170,15 @@ public boolean isSelfAssignment() {
}
}

private boolean hasAssignmentOperator(Node node) {
if (node instanceof ASTStatementExpression || node instanceof ASTExpression) {
if (node.jjtGetNumChildren() >= 2 && node.jjtGetChild(1) instanceof ASTAssignmentOperator) {
return true;
}
}
return false;
}

/**
* Simply return true is the image is equal to keyword 'this' or 'super'.
*
Original file line number Diff line number Diff line change
@@ -310,4 +310,27 @@ public class MyClass {
}
]]></code>
</test-code>
<test-code>
<description>
3526212, pmd-5.0.0: ImmutableField false positive on self-inc/dec
</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class pmd_inc {
private int test;
public pmd_inc() {
this.test = 2;
}
public int get_test() {
return this.test;
}
public void inc_test(int val) {
this.test += val;
}
}
]]></code>
</test-code>
</test-data>

0 comments on commit eb6c0c8

Please sign in to comment.