Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6394757

(coll) AbstractSet.removeAll semantics are surprisingly dependent on relative sizes

XMLWordPrintable

      One would think that the following program
      ---------------------------
      import java.util.*;

      public class Bug {
          static void test(String... elts) {
              Set<String> s = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
              s.addAll(Arrays.asList("a", "b"));
              s.removeAll(Arrays.asList(elts));
              System.out.println(s);
          }

          public static void main(String[] args) {
              test("A");
              test("A", "C");
          }
      }
      ---------------------------

      would print 2 identical lines, but in fact it prints

      [b]
      [a, b]

      The results are dependent on the relative sizes of the two sets,
      violating the Principle of Least Astonishment.

            smarks Stuart Marks
            martin Martin Buchholz
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: