Skip to content

Commit

Permalink
Suppress callsites where the return value of Comparator.compare is …
Browse files Browse the repository at this point in the history
…unused.

PiperOrigin-RevId: 491402529
  • Loading branch information
cpovirk authored and Google Java Core Libraries committed Nov 28, 2022
1 parent 942ec29 commit 38ce3d0
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ private <T> T checkValid(T t) {
// a ClassCastException is what's supposed to happen!
@SuppressWarnings("unchecked")
K k = (K) t;
comparator().compare(k, k);
int unused = comparator().compare(k, k);
return t;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ private <T> T checkValid(T t) {
// a ClassCastException is what's supposed to happen!
@SuppressWarnings("unchecked")
E e = (E) t;
comparator().compare(e, e);
int unused = comparator().compare(e, e);
return t;
}

Expand Down
10 changes: 6 additions & 4 deletions android/guava/src/com/google/common/collect/GeneralRange.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,14 @@ private GeneralRange(
* whenever they pass `true` for the matching `has*Bound` parameter.
*/
if (hasLowerBound) {
comparator.compare(
uncheckedCastNullableTToT(lowerEndpoint), uncheckedCastNullableTToT(lowerEndpoint));
int unused =
comparator.compare(
uncheckedCastNullableTToT(lowerEndpoint), uncheckedCastNullableTToT(lowerEndpoint));
}
if (hasUpperBound) {
comparator.compare(
uncheckedCastNullableTToT(upperEndpoint), uncheckedCastNullableTToT(upperEndpoint));
int unused =
comparator.compare(
uncheckedCastNullableTToT(upperEndpoint), uncheckedCastNullableTToT(upperEndpoint));
}

if (hasLowerBound && hasUpperBound) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ SortedSet<V> createCollection() {
@Override
Collection<V> createCollection(@ParametricNullness K key) {
if (key == null) {
keyComparator().compare(key, key);
int unused = keyComparator().compare(key, key);
}
return super.createCollection(key);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public int add(@ParametricNullness E element, int occurrences) {
checkArgument(range.contains(element));
AvlNode<E> root = rootReference.get();
if (root == null) {
comparator().compare(element, element);
int unused = comparator().compare(element, element);
AvlNode<E> newRoot = new AvlNode<E>(element, occurrences);
successor(header, newRoot, header);
rootReference.checkAndSet(root, newRoot);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ private <T> T checkValid(T t) {
// a ClassCastException is what's supposed to happen!
@SuppressWarnings("unchecked")
K k = (K) t;
comparator().compare(k, k);
int unused = comparator().compare(k, k);
return t;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ private <T> T checkValid(T t) {
// a ClassCastException is what's supposed to happen!
@SuppressWarnings("unchecked")
E e = (E) t;
comparator().compare(e, e);
int unused = comparator().compare(e, e);
return t;
}

Expand Down
10 changes: 6 additions & 4 deletions guava/src/com/google/common/collect/GeneralRange.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,14 @@ private GeneralRange(
* whenever they pass `true` for the matching `has*Bound` parameter.
*/
if (hasLowerBound) {
comparator.compare(
uncheckedCastNullableTToT(lowerEndpoint), uncheckedCastNullableTToT(lowerEndpoint));
int unused =
comparator.compare(
uncheckedCastNullableTToT(lowerEndpoint), uncheckedCastNullableTToT(lowerEndpoint));
}
if (hasUpperBound) {
comparator.compare(
uncheckedCastNullableTToT(upperEndpoint), uncheckedCastNullableTToT(upperEndpoint));
int unused =
comparator.compare(
uncheckedCastNullableTToT(upperEndpoint), uncheckedCastNullableTToT(upperEndpoint));
}

if (hasLowerBound && hasUpperBound) {
Expand Down
2 changes: 1 addition & 1 deletion guava/src/com/google/common/collect/TreeMultimap.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ SortedSet<V> createCollection() {
@Override
Collection<V> createCollection(@ParametricNullness K key) {
if (key == null) {
keyComparator().compare(key, key);
int unused = keyComparator().compare(key, key);
}
return super.createCollection(key);
}
Expand Down
2 changes: 1 addition & 1 deletion guava/src/com/google/common/collect/TreeMultiset.java
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ public int add(@ParametricNullness E element, int occurrences) {
checkArgument(range.contains(element));
AvlNode<E> root = rootReference.get();
if (root == null) {
comparator().compare(element, element);
int unused = comparator().compare(element, element);
AvlNode<E> newRoot = new AvlNode<E>(element, occurrences);
successor(header, newRoot, header);
rootReference.checkAndSet(root, newRoot);
Expand Down

0 comments on commit 38ce3d0

Please sign in to comment.