[java] UselessOperationOnImmutable: false positive on void results
This commit is contained in:
@ -30,7 +30,8 @@ public class UselessOperationOnImmutableRule extends AbstractJavaRulechainRule {
|
||||
@Override
|
||||
public Object visit(ASTMethodCall node, Object data) {
|
||||
ASTExpression qualifier = node.getQualifier();
|
||||
if (node.getParent() instanceof ASTExpressionStatement && qualifier != null) {
|
||||
boolean returnsVoid = node.getTypeMirror().isVoid();
|
||||
if (node.getParent() instanceof ASTExpressionStatement && qualifier != null && !returnsVoid) {
|
||||
|
||||
// these types are immutable, so any method of those whose
|
||||
// result is ignored is a violation
|
||||
|
@ -318,6 +318,20 @@ class Tester {
|
||||
period = period.plusWeeks(1); // ok
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
||||
<test-code>
|
||||
<description>False positive for package private method calls in openjdk</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
package java.time;
|
||||
import java.io.ObjectOutput;
|
||||
class Tester {
|
||||
static void writeExternal(ZonedDateTime zonedDateTime, ObjectOutput out) {
|
||||
zonedDateTime.writeExternal(out); // false positive
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
</test-data>
|
||||
|
Reference in New Issue
Block a user