Skip to content
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

UnnecessaryParentheses: no violation if casting is present before expression #14872

Open
romani opened this issue May 12, 2024 · 0 comments
Open
Labels

Comments

@romani
Copy link
Member

romani commented May 12, 2024

detected at https://github.com/checkstyle/checkstyle/pull/14856/files#r1597531069

I have read check documentation: https://checkstyle.org/checks/coding/unnecessaryparentheses.html#UnnecessaryParentheses
I have downloaded the latest checkstyle from: https://checkstyle.org/cmdline.html#Download_and_Run
I have executed the cli and showed it below, as cli describes the problem better than 1,000 words

$ cat config.xml 
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
          "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
          "https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="Checker">
  <module name="TreeWalker">
    <module name="UnnecessaryParentheses">
    </module>
  </module>
</module>

$ cat Test.java 
import java.util.Arrays;

public class Test
{
  public static void main(String[] args) {
    String[] a = { "s", "", "1", "", "" };
    Arrays.stream(a).filter(s -> !((boolean)s.isEmpty())).toArray(String[]::new); // should be violation
    Arrays.stream(a).filter(s -> !(boolean)s.isEmpty()).toArray(String[]::new);
  }
}

$ java -jar checkstyle-10.16.0-all.jar -c config.xml Test.java
Starting audit...
Audit done.

Expected: violation on line 7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant