-
Notifications
You must be signed in to change notification settings - Fork 147
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
Labels
Comments
Yes, this only for non side effect methods. We need to improve javadoc to mention this Line 28 in c1a9944
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
return executeEmergencyBreak() && someCondition;
cannot be optimized toreturn someCondition && executeEmergencyBreak();
, because the second piece of code will not trigger the emergency brake anymore, ifsomeCondition
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.
The text was updated successfully, but these errors were encountered: