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

LogicConditionNeedOptimization is based on a wrong idea #1025

Open
Bananeweizen opened this issue Sep 11, 2023 · 1 comment
Open

LogicConditionNeedOptimization is based on a wrong idea #1025

Bananeweizen opened this issue Sep 11, 2023 · 1 comment
Labels

Comments

@Bananeweizen
Copy link
Contributor

Bananeweizen commented Sep 11, 2023

return executeEmergencyBreak() && someCondition; cannot be optimized to return someCondition && executeEmergencyBreak();, because the second piece of code will not trigger the emergency brake anymore, if someCondition is true.

Generally speaking, the re-ordering of expressions inside boolean operators is only allowed, if the short-circuit evaluation does not prohibit any side effects (that is any change of global state, like hitting the brakes) that would have occurred without the reordering.

Therefore this rule is only valid for methods that are known to have no side effect, but not for general Java methods being called.

@romani
Copy link
Member

romani commented Sep 11, 2023

Yes, this only for non side effect methods.

We need to improve javadoc to mention this

* This check prevents the placement of local variables and fields after calling

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

No branches or pull requests

2 participants