Fix statement cast in UselessOverridingMethodRule class.

Summary: Now using the parent Node class to avoid the ClassCastException.

Test Plan: Added new test for the modified class. Run tests

Reviewers: jmsotuyo

Reviewed By: jmsotuyo

Differential Revision: http://ph.monits.com/D12213
This commit is contained in:
José Manuel Rolón
2015-08-19 17:29:48 -03:00
parent 62202a5293
commit 3cf58cb43a
2 changed files with 25 additions and 2 deletions

View File

@ -130,7 +130,7 @@ public class UselessOverridingMethodRule extends AbstractJavaRule {
return super.visit(node, data);
}
ASTStatement statement = (ASTStatement) block.jjtGetChild(0).jjtGetChild(0);
Node statement = block.jjtGetChild(0).jjtGetChild(0);
if (statement.jjtGetChild(0).jjtGetNumChildren() == 0) {
return data; // skips empty return statements
}

View File

@ -373,5 +373,28 @@ public class Example extends PersistentObject {
}
]]></code>
</test-code>
<test-code>
<description><![CDATA[
ClassCastException in statement cast
]]></description>
<expected-problems>0</expected-problems>
<code><![CDATA[
import java.util.Comparator;
import javax.annotation.Nonnull;
</test-data>
public class AnonymousClassConstructor {
public void method() {
@SuppressWarnings("unused")
final Comparator<Long> comparator = new Comparator<Long>() {
@Override
public int compare(@Nonnull Long o1, @Nonnull Long o2) {
return 0;
}
};
}
}
]]></code>
</test-code>
</test-data>