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

[java] SimplifiedTernary: support for the java.lang.Boolean class #3604

Open
dykov opened this issue Nov 7, 2021 · 1 comment
Open

[java] SimplifiedTernary: support for the java.lang.Boolean class #3604

dykov opened this issue Nov 7, 2021 · 1 comment
Labels
an:enhancement An improvement on existing features / rules

Comments

@dykov
Copy link

dykov commented Nov 7, 2021

Is your feature request related to a problem? Please describe.
I faced ternary operators with Boolean objects as result:

condition ? Boolean.TRUE : something(); // can be as simple as condition || something()

Describe the solution you'd like
In my opinion, it would be a good solution to disable the use of this class. just like the boolean in the original rule.

@dykov dykov added the an:enhancement An improvement on existing features / rules label Nov 7, 2021
@oowekyala
Copy link
Member

If something() returns null and you've refactored to condition || something() then your expression NPEs. This is not a problem with a boolean literal (eg condition ? true : (Boolean) null) because that code NPEs too.

I think maybe, UnnecessaryBoxing could carefully* look into whether Boolean.TRUE may be unboxed to true (which here it can't). If it can then SimplifiedTernary would flag it. I don't think this case should be added to SimplifiedTernary.

* boxing rules in ternaries with a primitive type are very complicated...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
an:enhancement An improvement on existing features / rules
Projects
None yet
Development

No branches or pull requests

2 participants