code: static boolean safeContains(Collection<?> collection, @Nullable Object object) {
      checkNotNull(collection);
      try {
        return collection.contains(object);
      } catch (ClassCastException e) {
        return false;
      } catch (NullPointerException e) {
        return false;
      }
    }
docs: Delegates to {@link Collection#contains}. Returns {@code false} if the
  {@code contains} method throws a {@code ClassCastException} or
  {@code NullPointerException}.