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

Use Boolean.equals instead of == when comparing Boolean objects #154

Merged
merged 3 commits into from
Mar 18, 2020

Conversation

dwnusbaum
Copy link
Member

It is safer to use Boolean.equals instead of == when comparing nullable Boolean objects in case one of the objects was constructed via new Boolean(boolean), which creates distinct objects.

I don't think that this code ever uses new Boolean(boolean), but it doesn't hurt to make the code more robust just in case.

FlowExecution fetchedExecution = getExecution(); // Triggers execution.onLoad so we can resume running if not done

if (fetchedExecution != null) {
if (completed == null) {
completed = Boolean.valueOf(fetchedExecution.isComplete());
}

if (!completed == Boolean.TRUE) {
if (Boolean.FALSE.equals(completed)) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Unrelated to the other changes. The old code was fine, since we check completed == null a few lines up and set it to a non-null value, but unnecessarily roundabout, since it was unboxing the Boolean to a boolean, then inverting that and comparing the inverted result to Boolean.TRUE, which was also unboxed into a boolean. Much clearer in my opinion to just compare to Boolean.FALSE directly.

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.

4 participants