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

AvoidNotShortCircuitOperatorsForBoolean: reports multi catch case #659

Closed
toli opened this Issue Apr 11, 2018 · 2 comments

Comments

Projects
None yet
3 participants
@toli
Copy link

toli commented Apr 11, 2018

seems that another variant of #559 is back.

seems that if i have a complex multi-line command before the catch with multiple exceptions i get the same incorrect behavior
attaching a pom.xml, java file and the config.xml to run mvn checkstyle:checkstyle

/var/tmp $ javac YOUR_FILE.java
compiles via Maven

/var/tmp $ cat YOUR_FILE.java

import com.spotify.docker.client.DockerClient;
import com.spotify.docker.client.exceptions.DockerException;
import com.spotify.docker.client.messages.ContainerConfig;
import com.spotify.docker.client.messages.HostConfig;

import java.util.concurrent.ExecutorService;

public class Toli {
  // this will obviously not run at all..
  private void updateDelegateViaDocker(String newVersion) {
    ExecutorService executorService = null;
    executorService.submit(() -> {
      try {
        HostConfig hostConfig = null;
        ContainerConfig containerConfig = ContainerConfig.builder()
            .image("toliImage")
            .attachStderr(true)
            .hostConfig(HostConfig.builder().build()).build();
        DockerClient docker = null;
        docker.startContainer(docker.createContainer(containerConfig).id());

      } catch (InterruptedException | DockerException ex) {
        // boo
      }
    });
  }
}

/var/tmp $ cat config.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC
        "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
        "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">

<module name="Checker">
    <module name="TreeWalker">
        <module name="AvoidNotShortCircuitOperatorsForBoolean"/>
        <module name="com.github.sevntu.checkstyle.checks.coding.AvoidNotShortCircuitOperatorsForBooleanCheck"/>
    </module>
</module>

For Linux users:

java -classpath sevntu-checks-1.29.0.jar:checkstyle-8.9-all.jar com.puppycrawl.tools.checkstyle.Main -c config.xml src/main/java/Toli.java
Starting audit...
[ERROR] /private/tmp/checkstyle/src/main/java/Toli.java:22:37: Short-circuit operator should be used instead of '|'. [AvoidNotShortCircuitOperatorsForBoolean]
Audit done.
Checkstyle ends with 1 errors.

Expecting not to see the AvoidNotShortCircuitOperatorsForBoolean style error

AvoidNotShortCircuitOperatorsForBoolean.zip

@rnveach

This comment has been minimized.

Copy link
Contributor

rnveach commented Jun 8, 2018

Issue is directly related to lambda with try-multi-catch inside it.

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

@romani romani added the approved label Jun 8, 2018

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

@romani

This comment has been minimized.

Copy link
Member

romani commented Jun 8, 2018

fix is merged

@romani romani closed this Jun 8, 2018

@rnveach rnveach added the bug label Jun 23, 2018

@rnveach rnveach changed the title return of AvoidNotShortCircuitOperatorsForBoolean reports multi catch case AvoidNotShortCircuitOperatorsForBoolean: reports multi catch case 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