New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LogicConditionNeedOptimization: ignore instanceof #661

Closed
rnveach opened this Issue May 27, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@rnveach
Copy link
Contributor

rnveach commented May 27, 2018

$ cat TestClass.java
public class TestClass {
    void method() {
String s = "";
Object o = null;
if (("Package".equals(s)) && (o instanceof String)) {}
    }
}

$ 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:5: Condition with && at line 5 position 26 need optimization. All method calls are advised to move to end of logic expression. [LogicConditionNeedOptimization]
Audit done.
Checkstyle ends with 1 errors.

instanceof should be treated the same as a method call as it is a heavy procedure.

@romani romani added the approved label May 27, 2018

rnveach added a commit to rnveach/sevntu.checkstyle that referenced this issue Jun 8, 2018

rnveach added a commit to rnveach/sevntu.checkstyle that referenced this issue Jun 8, 2018

rnveach added a commit to rnveach/sevntu.checkstyle that referenced this issue Jun 8, 2018

rnveach added a commit to rnveach/sevntu.checkstyle that referenced this issue Jun 8, 2018

rnveach added a commit to rnveach/sevntu.checkstyle that referenced this issue Jun 8, 2018

rnveach added a commit that referenced this issue Jun 8, 2018

@rnveach

This comment has been minimized.

Copy link
Contributor

rnveach commented Jun 8, 2018

Fix was merged

@rnveach rnveach closed this Jun 8, 2018

@romani romani added this to the 1.30.0 milestone Jun 8, 2018

@rnveach rnveach added the bug label Jun 23, 2018

kariem added a commit to kariem/sevntu.checkstyle that referenced this issue Jul 26, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment