You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Alex Herbert (Jira)" <ji...@apache.org> on 2020/03/08 23:30:00 UTC
[jira] [Closed] (COLLECTIONS-756) CollectionUtils.filter(..) broken
with blank Collections.singleton
[ https://issues.apache.org/jira/browse/COLLECTIONS-756?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Alex Herbert closed COLLECTIONS-756.
------------------------------------
Resolution: Not A Problem
From the Javadoc for {{Collections.singleton(T o)}}:
{noformat}
Returns an immutable set containing only the specified object.
{noformat}
If the set is immutable you cannot expect any function to be able to change it based on a filter.
This will throw an exception:
{code:java}
Collections.singleton("").clear();
{code}
So don't expect CollectionUtils to be able to remove the blank string.
> CollectionUtils.filter(..) broken with blank Collections.singleton
> ------------------------------------------------------------------
>
> Key: COLLECTIONS-756
> URL: https://issues.apache.org/jira/browse/COLLECTIONS-756
> Project: Commons Collections
> Issue Type: Bug
> Components: Collection
> Affects Versions: 4.4
> Reporter: noname713705
> Priority: Major
>
> When using {{CollectionUtils.filter(..)}}, if the passed collection is initialized with jdk {{Collections.singleton(..)}} and only contains an {{isBlank(..)}} string, the method will throw an exception instead of removing blank item as expected. Tested with commons-collections:4.4 and java8.
> All can be resumed with
> {code:java}
> CollectionUtils.filter(Collections.singleton(" "), StringUtils::isNotBlank); {code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)