Java Commons集合removeAll

Java Commons集合removeAll,java,collections,apache-commons-collection,Java,Collections,Apache Commons Collection,我一定是疯了,因为这种方法似乎与文档的状态相反: 移除“从集合中移除”中的元素。也就是说,此方法返回一个集合,其中包含c中不在remove中的所有元素 这个小小的JUnit测试 @Test public void testCommonsRemoveAll() throws Exception { String str1 = "foo"; String str2 = "bar"; String str3 = "qux"; List<String> co

我一定是疯了,因为这种方法似乎与文档的状态相反:

移除“从集合中移除”中的元素。也就是说,此方法返回一个集合,其中包含c中不在remove中的所有元素

这个小小的JUnit测试

@Test
public void testCommonsRemoveAll() throws Exception {
    String str1 = "foo";
    String str2 = "bar";
    String str3 = "qux";

    List<String> collection = Arrays.asList(str1, str2, str3);
    System.out.println("collection: " + collection);

    List<String> remove = Arrays.asList(str1);
    System.out.println("remove: " + remove);

    Collection result = CollectionUtils.removeAll(collection, remove);
    System.out.println("result: " + result);
    assertEquals(2, result.size());
}

从我对文档的阅读来看,我应该期望
[bar,qux]
。我错过了什么?

编辑2014年1月1日Apache Commons Collections 4.0终于在2013年11月21日发布,并包含了此问题的修复程序

有问题的行(1688-1691),确认该方法之前已被破坏:

/*
 ...
 * @since 4.0 (method existed in 3.2 but was completely broken)
 */
public static <E> Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove) {
    return ListUtils.removeAll(collection, remove);
}

是的……坏了

天哪!那是怎么从裂缝中滑出来的?谢谢你的信息。为您投票并接受。@markdsievers-看起来要么需要单元测试,要么需要修复!依我看,这很糟糕。错误是可以的,但是原始版本有一个“02/Aug/06 17:37”的创建标记,而且他们还没有发布一个包含修复的生产版本。@StephenC-这非常糟糕,即使是补丁发布也比等待主干发布要好,Apache Commons Collections上一次发布是在2008年4月的3.2.1版。也许没有人认为这是一个大问题,或者他们不知道它被破坏了,到处都是代码库中的问题。对于任何感兴趣的人来说,我的解决方案是直接使用这个方法的意图,即ListUtils.removeAll(a,b).我更新了我的帖子以反映这一点,因为有人提醒我——但Apache Commons Collections 4.0于2013年11月发布,并对此问题进行了修复。
/*
 ...
 * @since 4.0 (method existed in 3.2 but was completely broken)
 */
public static <E> Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove) {
    return ListUtils.removeAll(collection, remove);
}
public static Collection removeAll(Collection collection, Collection remove) {
    return ListUtils.retainAll(collection, remove);
}