You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-issues@jackrabbit.apache.org by "Rishabh Daim (Jira)" <ji...@apache.org> on 2025/01/30 12:19:00 UTC
[jira] [Comment Edited] (OAK-11442) Remove usage of Guava Iterables.contains
[ https://issues.apache.org/jira/browse/OAK-11442?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17922353#comment-17922353 ]
Rishabh Daim edited comment on OAK-11442 at 1/30/25 12:18 PM:
--------------------------------------------------------------
There is an api present in commons-collection4 to check whether an element is present inside the iterable or not, but there are subtle differences between Guava's & Apache's implementation as explained below:
# The [Iterables.contains()|https://javadoc.scijava.org/Guava/com/google/common/collect/Iterators.html#contains(java.util.Iterator,java.lang.Object)] from Guava returns true if the iterable contains the element but in case of exceptions (Class Cast & Null Pointer) it returns false instead of throwing the exception. Whereas the [IterableUtils.contains()|https://commons.apache.org/proper/commons-collections/apidocs/org/apache/commons/collections4/IterableUtils.html#contains(java.lang.Iterable,java.lang.Object)] from commons-collections4 would might throws the exception in case of class cast or Null pointer.
# If both the Iterable & objects are empty then *Guava* *Iterables.contains* would return true but *commons-collections4 IterableUtils.contains()* would return false.
cc [~reschke] [~baedke]
was (Author: JIRAUSER299730):
There is an api present in commons-collection4 to check whether an element is present inside the iterable or not, but there are subtle differences between Guava's & Apache's implementation as explained below:
The [Iterables.contains()|https://javadoc.scijava.org/Guava/com/google/common/collect/Iterators.html#contains(java.util.Iterator,java.lang.Object)] from Guava returns true if the iterable contains the element but in case of exceptions (Class Cast & Null Pointer) it returns false instead of throwing the exception. Whereas the [IterableUtils.contains()|https://commons.apache.org/proper/commons-collections/apidocs/org/apache/commons/collections4/IterableUtils.html#contains(java.lang.Iterable,java.lang.Object)] from commons-collections4 would might throws the exception in case of class cast or Null pointer.
Another difference is that, if both the Iterable & objects are empty then *Guava* *Iterables.contains* would return true but *commons-collections4 IterableUtils.contains()* would return false.
cc [~reschke] [~baedke]
> Remove usage of Guava Iterables.contains
> ----------------------------------------
>
> Key: OAK-11442
> URL: https://issues.apache.org/jira/browse/OAK-11442
> Project: Jackrabbit Oak
> Issue Type: Technical task
> Reporter: Rishabh Daim
> Assignee: Rishabh Daim
> Priority: Major
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)