Skip to content

Commit

Permalink
Thread safety concern due to "memory barrier" in FcnRcdValue#select.
Browse files Browse the repository at this point in the history
* Defensively check Value#equals in addition to Value#compareTo.

Part of Github #439
#439

[Performance][TLC]
  • Loading branch information
lemmy committed Dec 2, 2021
1 parent 4487aa6 commit 174919c
Showing 1 changed file with 4 additions and 1 deletion.
Expand Up @@ -440,7 +440,10 @@ final Value selectBinarySearch(final Value arg) {
// cast to int is the same as flooring for positive ints.
final int mid = (low + high) >>> 1;
final int cmp = this.domain[mid].compareTo(arg);
if (cmp == 0) {
if (cmp == 0 && this.domain[mid].equals(arg)) {
// Check equality and cmp here to not introduce subtle bugs with Value#compareTo
// behaving slightly differently for some types. Linear search and the old,
// hash-based lookup use/used Value#equals.
return this.values[mid];
} else if (cmp < 0) {
low = mid + 1;
Expand Down

0 comments on commit 174919c

Please sign in to comment.