You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$ cat TestClass.java
public class TestClass {
private int field = 1;
void method() {
TestClass s = new TestClass(), t = null, u = null;
// original
if (((t = s).test()) &&
((u = t).field == 1) != null &&
(u.field) != 2) {}
// bad fix
if (((u = t).field == 1) != null &&
(u.field) != 2 &&
((t = s).test())) {}
}
public boolean test() { return true; }
}
$ cat TestConfig.xml
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
<module name="Checker">
<property name="charset" value="UTF-8"/>
<module name="TreeWalker">
<module name="com.github.sevntu.checkstyle.checks.coding.LogicConditionNeedOptimizationCheck" />
</module>
</module>
$ java -jar checkstyle-8.9-sevntu-1.29.0-all.jar -c TestConfig.xml TestClass.java
Starting audit...
[ERROR] TestClass.java:8: Condition with && at line 8 position 29 need optimization. All method calls are advised to move to end of logic expression. [LogicConditionNeedOptimization]
[ERROR] TestClass.java:9: Condition with && at line 9 position 41 need optimization. All method calls are advised to move to end of logic expression. [LogicConditionNeedOptimization]
Audit done.
Checkstyle ends with 2 errors.
Re-arranging any of the conditions will cause an NPE. In other circumstances it could cause unwanted behavior from using old values from previous iteration, like the instanceof example.
The text was updated successfully, but these errors were encountered:
Identified at #678 (comment) ,
Re-arranging any of the conditions will cause an NPE. In other circumstances it could cause unwanted behavior from using old values from previous iteration, like the
instanceof
example.The text was updated successfully, but these errors were encountered: