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

SONARJAVA-5341 Fix FP reported for too many cases on switches when enum types are unknown #5041

Merged
merged 3 commits into from
Feb 26, 2025

Conversation

romainbrenguier
Copy link
Contributor

@romainbrenguier romainbrenguier commented Feb 26, 2025

SONARJAVA-5341

When we don't know if the symbol in the switch is an enum, we shouldn't raise that issue.

Comment on lines 25 to 28
public static TernaryValue ofBoolean(@Nullable Boolean b) {
if (b == null) {
return UNKNOWN;
}
return b ? TRUE : FALSE;
}

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure about the usefulness of ofBoolean compared to of, I don't see where there could be ambiguity.
When we have a boolean like isEnum(), I would prefer having a dedicated method instead of converting it to Boolean in a method that converts it back to boolean.

Suggested change
public static TernaryValue ofBoolean(@Nullable Boolean b) {
if (b == null) {
return UNKNOWN;
}
return b ? TRUE : FALSE;
}
public static TernaryValue of(boolean b) {
return b ? TRUE : FALSE;
}
public static TernaryValue of(@Nullable Boolean b) {
return b == null ? UNKNOWN : of(b.booleanValue());
}

@romainbrenguier romainbrenguier force-pushed the romain/fix-fp-enum-switch branch from b03a509 to 55ceea5 Compare February 26, 2025 14:31
Copy link

sonarqube-next bot commented Feb 26, 2025

@alban-auzeill alban-auzeill merged commit 87ca4d1 into master Feb 26, 2025
15 of 16 checks passed
@alban-auzeill alban-auzeill deleted the romain/fix-fp-enum-switch branch February 26, 2025 14:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants