Skip to content

Commit

Permalink
resilience: don't compare Integer objects by refference
Browse files Browse the repository at this point in the history
Motivation:
Though Integer objects are often unboxed for arithmetic operations, a
direct equality check of two instances with '==' operator checks only
for instance reference level equality. As boxing uses Integer#valueOf,
for values below 127 such check can accidentally work.

Modification:
Use Objects#equals to check equality by value and handle  possible 'null'
value cases.

Result:
fix equality check of replica count.

Acked-by: Paul Millar
Acked-by: Albert Rossi
Target: master, 6.0, 5.2, 5.1, 5.0, 4.2
Require-book: no
Require-notes: yes
  • Loading branch information
kofemann committed Oct 23, 2019
1 parent 71dfffa commit 053dd1f
Showing 1 changed file with 2 additions and 1 deletion.
Expand Up @@ -62,6 +62,7 @@ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
import com.google.common.collect.ImmutableSet;

import java.util.Collection;
import java.util.Objects;
import java.util.Set;

/**
Expand Down Expand Up @@ -92,7 +93,7 @@ public final class StorageUnitConstraints extends ResilienceMarker {
}

public boolean equals(StorageUnitConstraints constraints) {
return constraints != null && this.required == constraints.required
return constraints != null && Objects.equals(this.required, constraints.required)
&& this.oneCopyPer.equals(constraints.oneCopyPer);
}

Expand Down

0 comments on commit 053dd1f

Please sign in to comment.