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

NoWhitespaceAfter false positive on synchronized method #12486

Closed
ctabin opened this issue Dec 1, 2022 · 4 comments · Fixed by #12487
Closed

NoWhitespaceAfter false positive on synchronized method #12486

ctabin opened this issue Dec 1, 2022 · 4 comments · Fixed by #12487
Assignees
Milestone

Comments

@ctabin
Copy link

ctabin commented Dec 1, 2022

Hello,

I have the following checkstyle configuration in pom.xml:

<module name="NoWhitespaceAfter">
      <property name="tokens" value="ARRAY_INIT,AT,INC,DEC,UNARY_MINUS,UNARY_PLUS,BNOT,LNOT,DOT,TYPECAST,ARRAY_DECLARATOR,INDEX_OP,LITERAL_SYNCHRONIZED,METHOD_REF" />
</module>

With a mvn verify, the following piece of code reports an error 'synchronized' is followed by whitespace:

public class TestClass {
    private synchronized Row waitForNextRow() {
    }
}

It seems to be a false positive because the check should only apply on structures like:

synchronized(lock) { ... }

Here is the output:

$ cat TestClass.java
public class TestClass {
    private synchronized Row waitForNextRow() {
    }
}

$ cat TestConfig.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">
    <property name="charset" value="UTF-8"/>

    <module name="TreeWalker">
<module name="NoWhitespaceAfter">
      <property name="tokens" value="ARRAY_INIT,AT,INC,DEC,UNARY_MINUS,UNARY_PLUS,BNOT,LNOT,DOT,TYPECAST,ARRAY_DECLARATOR,INDEX_OP,LITERAL_SYNCHRONIZED,METHOD_REF" />
</module>
    </module>
</module>

$ java -jar checkstyle-10.5.0-all.jar -c TestConfig.xml TestClass.java
Starting audit...
[ERROR] TestClass.java:2:13: 'synchronized' is followed by whitespace. [NoWhitespaceAfter]
Audit done.
Checkstyle ends with 1 errors.

Thanks & best regards.

@ctabin
Copy link
Author

ctabin commented Dec 1, 2022

@rnveach Oops it seems you edited my comments and I edited them back behind, sorry. Don't hesitate if you think I'm missing some important information.

@rnveach
Copy link
Member

rnveach commented Dec 1, 2022

We ask for issues to reported in our format https://checkstyle.org/report_issue.html#How_to_report_a_bug.3F

@ctabin
Copy link
Author

ctabin commented Dec 1, 2022

@rnveach Thanks. I put back the output you've added previously. Hope it is good.

@nrmancuso nrmancuso added the bug label Dec 2, 2022
@nrmancuso nrmancuso self-assigned this Dec 2, 2022
@nrmancuso
Copy link
Member

I am on it

nrmancuso added a commit to nrmancuso/checkstyle that referenced this issue Dec 2, 2022
nrmancuso added a commit to nrmancuso/checkstyle that referenced this issue Dec 2, 2022
nrmancuso added a commit to nrmancuso/checkstyle that referenced this issue Dec 2, 2022
nrmancuso added a commit to nrmancuso/checkstyle that referenced this issue Dec 2, 2022
nrmancuso added a commit to nrmancuso/checkstyle that referenced this issue Dec 2, 2022
nrmancuso added a commit to nrmancuso/checkstyle that referenced this issue Dec 2, 2022
nrmancuso added a commit to nrmancuso/checkstyle that referenced this issue Dec 7, 2022
nrmancuso added a commit to nrmancuso/checkstyle that referenced this issue Dec 7, 2022
nrmancuso added a commit to nrmancuso/checkstyle that referenced this issue Dec 7, 2022
nrmancuso added a commit to nrmancuso/checkstyle that referenced this issue Dec 10, 2022
@romani romani added this to the 10.5.1 milestone Dec 10, 2022
@romani romani changed the title NoWhitespaceAfter synchronized method NoWhitespaceAfter false positive on synchronized method Dec 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants