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

Issue #13553: False positive in FallThroughCheck on last case #14734

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Lmh-java
Copy link
Contributor

@Lmh-java Lmh-java commented Mar 29, 2024

Fix for Issue #13553, Continue of #14016

Config

<module name="FallThrough">
    <property name="checkLastCaseGroup" value="true"/>
</module>

Regression Report

https://checkstyle-diff-reports.s3.us-east-2.amazonaws.com/8a0a354_2024060435/reports/diff/checkstyle/index.html
5 violations are removed in Checkstyle code base. Differences in this report are intended.

For example:

void method5(int i, int j, boolean cond) {
      while (true) {
          switch (i){
          case 5: // violation 'Fall\ through from the last branch of the switch statement'
              i++;
              /* block */ /* fallthru */ // comment
          }
      }
   }

This is no longer a violation in this case. Same for the other 4 cases.

Diff Regression config: https://gist.githubusercontent.com/Lmh-java/55bdd9e289522aff23374ad7b5571c2c/raw/4e52c69d3888eff5f976f0ae87c058e98c0dd72d/input-fall-thru-config.xml

@Lmh-java Lmh-java marked this pull request as draft March 30, 2024 00:58
@Lmh-java Lmh-java force-pushed the minghao/false-positive-fallthru branch 3 times, most recently from 06a1b46 to 8a0a354 Compare March 30, 2024 04:48
@Lmh-java
Copy link
Contributor Author

GitHub, generate report

@Lmh-java Lmh-java marked this pull request as ready for review March 30, 2024 05:28
}
}

return hasReliefComment;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactor hasReliefComment

the warning or on the same line before the {@code case}(ugly, but possible).
The comment containing these words must be on the last non-empty line
before the {@code case} triggering the warning or on the same line before
the {@code case}(ugly, but possible).
Copy link
Contributor Author

@Lmh-java Lmh-java Mar 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the sentence in the doc as required

Copy link
Member

@rnveach rnveach Apr 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update in doc to remove:

The comment containing these words must be all on one line

I don't remember this conversation regarding this but does this mean if I have a suppression word as "suppress me", it will match things like "suppress \n me"? Do you have a test example showing this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your updated documentation says:

...on the same line before the ...

How is that different then ...must be all on one line...?

Copy link
Contributor Author

@Lmh-java Lmh-java Apr 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update in doc to remove:

The comment containing these words must be all on one line

I don't remember this conversation regarding this but does this mean if I have a suppression word as "suppress me", it will match things like "suppress \n me"? Do you have a test example showing this?

No, I don't think "suppress \n me" will match.
This is matching by the pattern

    private Pattern reliefPattern = Pattern.compile("falls?[ -]?thr(u|ough)");

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your updated documentation says:

...on the same line before the ...

How is that different then ...must be all on one line...?

I didn't see the conversion about this part either, but I think "must be all on one line" is redundant and confusing. I don't really understand what it means. The subject of this sentence is "the comment containing these words". However, we only need one "comment" containing these words to suppress this check for that branch.

If we remove this "must be all on one line.", and updated it to

The comment containing these words must be on the last non-empty line
before the {@code case} triggering the warning or on the same line before
the {@code case}(ugly, but possible).

I think this might be able to explain everything?

Copy link
Member

@rnveach rnveach May 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like comment in issue came from #12966 (comment) . This was about "the last comment on that line". This is why the issue has /* block */ /* fallthru */ // comment.

If you agree, please restore original wording and add some wording that it can be any comment on that line.

Can you point to keywords where the suppression text is not the last comment on the line. If we don't have one, then create it and point to it.

Example:
/* trigger */ /* comment */ // last
/* comment */ /* fallthru */ // last

@Lmh-java
Copy link
Contributor Author

@nrmancuso @romani please take a look.

@nrmancuso nrmancuso self-assigned this Mar 30, 2024
@nrmancuso nrmancuso self-requested a review March 30, 2024 16:44
@nrmancuso
Copy link
Member

nrmancuso commented Apr 15, 2024

Rebasing on latest master, good to merge

@nrmancuso nrmancuso force-pushed the minghao/false-positive-fallthru branch from 8a0a354 to 988b8b0 Compare April 15, 2024 12:37
@nrmancuso nrmancuso assigned rnveach and unassigned nrmancuso Apr 15, 2024
@nrmancuso nrmancuso requested a review from rnveach April 15, 2024 12:38
Copy link
Member

@romani romani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok to merge

@rnveach
Copy link
Member

rnveach commented Apr 20, 2024

Edit: I am removing this. Property is additive, not either/or.

@Lmh-java Lmh-java force-pushed the minghao/false-positive-fallthru branch 4 times, most recently from 0d8f015 to 4b753cf Compare April 26, 2024 07:00
@rnveach rnveach removed their assignment Apr 26, 2024
@Lmh-java
Copy link
Contributor Author

GitHub, generate report

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

Successfully merging this pull request may close these issues.

None yet

4 participants