< prev index next >

test/jdk/java/util/Collections/T6433170.java

Print this page
@@ -1,7 +1,7 @@
  /*
-  * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+  * Copyright (c) 2007, 2026, Oracle and/or its affiliates. All rights reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.

@@ -23,12 +23,14 @@
  
  /*
   * @test
   * @bug 6433170
   * @summary CheckedCollection.addAll should be all-or-nothing
+  * @library /test/lib
   */
  
+ import jdk.test.lib.valueclass.VClass;
  import java.util.ArrayList;
  import java.util.Arrays;
  import java.util.Collection;
  import java.util.HashSet;
  import java.util.List;

@@ -38,10 +40,11 @@
  import static java.util.Collections.checkedList;
  import static java.util.Collections.checkedSet;
  
  @SuppressWarnings("unchecked")
  public class T6433170 {
+ 
      private void checkEmpty(Collection x) {
          check(x.isEmpty());
          check(x.size() == 0);
          check(x.toArray().length == 0);
      }

@@ -54,10 +57,16 @@
                   checkedSet(new HashSet(), String.class),
                   Object.class));
          test(checkedCollection(
                   checkedCollection(new Vector(), String.class),
                   Object.class));
+ 
+         Collection<VClass> vc = checkedCollection(new ArrayList<>(), VClass.class);
+         List mixed = Arrays.asList(new VClass(1, new int[] { 1 }), new VClass(2, new int[] { 2 }), "not a Tuple");
+         THROWS(ClassCastException.class,
+                new F(){void f(){ vc.addAll(mixed); }});
+         checkEmpty(vc);
      }
  
      void test(final Collection checked) {
          checkEmpty(checked);
          final List mixedList = Arrays.asList("1", 2, "3");
< prev index next >