Skip to content

Java: Add query to detect non-case labels in switch statements #19998

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

Merged
merged 2 commits into from
Jul 10, 2025

Conversation

tamasvajk
Copy link
Contributor

@tamasvajk tamasvajk commented Jul 8, 2025

This pull request introduces a new CodeQL query for detecting non-case labels in Java switch statements, which can be confusing or indicative of bugs.

This query was migrated from the internal repo. I somewhat changed the query to report two alert messages depending on whether the found label is used or not.

I've manually checked autofix suggestions on a couple of repos. Autofix can suggest both the trivial missing case keyword, and also can refactor the code, and move it into a separate method, and then call that method. (I guess the latter has some limitations, but my samples were relatively simple)

@tamasvajk tamasvajk marked this pull request as ready for review July 9, 2025 11:27
@Copilot Copilot AI review requested due to automatic review settings July 9, 2025 11:27
@tamasvajk tamasvajk requested a review from a team as a code owner July 9, 2025 11:27
@tamasvajk tamasvajk added no-change-note-required This PR does not need a change note ready-for-doc-review This PR requires and is ready for review from the GitHub docs team. labels Jul 9, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

subatoi
subatoi previously approved these changes Jul 10, 2025
Copy link
Contributor

@subatoi subatoi left a comment

Choose a reason for hiding this comment

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

I agree with the suggestions from Owen but otherwise looks good 👍

@owen-mc
Copy link
Contributor

owen-mc commented Jul 10, 2025

Tagging @knewbury01 for awareness.

@tamasvajk tamasvajk merged commit 1351f57 into github:main Jul 10, 2025
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Java no-change-note-required This PR does not need a change note ready-for-doc-review This PR requires and is ready for review from the GitHub docs team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants