This code uses
Object.equals (or similar method) with a type that does not
CharSequence. Such a call to
equals may return
cases where equality was expected.
equals, so will fall back to reference equality.
Your code might be working correctly, but only if there is some subtype of
Iterable which does have well-defined equals behavior, and you are certain
that both operands are definitely of that type at runtime. (The common examples
of such types are [
Multiset, or any subtypes of
If this describes your situation, congratulations: you don’t have a bug. To make
this warning go away, change the references in your code to be of that more
specific static type, not
Iterable. This lets the bug
checker (and human readers) know that there is no risk of a false negative.
The minimal solution is to cast or copy “just in time” before calling
but ideally you can make broader changes, to adopt the proper interface more
widely in your code.
On the other hand, if you might be mixing a
List and a non-
List, etc., you
are at risk. If you can’t correct that situation, one alternative solution is to
Iterables.elementsEqual (which checks for order-dependent equality,
There is no equivalent to
Iterables.elementsEqual in this case, however.
Queue implementations besides
LinkedList use reference equality
instead of value-based equality. Some of the workarounds discussed above may
When comparing a
String to a
When comparing the content of two
CharSequences, you may want to compare the
These must be iterated over and compared manually, element by element.
Suppress false positives by adding the suppression annotation
@SuppressWarnings("UndefinedEquals") to the enclosing element.