diff a/test/jdk/java/util/Collections/NCopies.java b/test/jdk/java/util/Collections/NCopies.java --- a/test/jdk/java/util/Collections/NCopies.java +++ b/test/jdk/java/util/Collections/NCopies.java @@ -1,7 +1,7 @@ /* - * Copyright (c) 2005, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 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. @@ -24,12 +24,14 @@ /* * @test * @bug 6267846 6275009 * @summary Test Collections.nCopies * @author Martin Buchholz + * @library /test/lib */ +import jdk.test.lib.valueclass.VClass; import java.util.ArrayList; import java.util.Collections; import java.util.AbstractList; import java.util.List; import java.util.Objects; @@ -140,10 +142,19 @@ check(copies.equals(copies.reversed())); List empty = Collections.nCopies(0, "content"); check(empty.equals(empty.reversed())); } + private static void checkValueCopies() { + List copies = Collections.nCopies(10, new VClass(7, new int[] { 7 })); + check(copies.indexOf(new VClass(7, new int[] { 7 })) == 0); + check(copies.lastIndexOf(new VClass(7, new int[] { 7 })) == 9); + check(copies.equals(referenceNCopies(10, new VClass(7, new int[] { 7 })))); + check(copies.hashCode() == referenceNCopies(10, new VClass(7, new int[] { 7 })).hashCode()); + check(copies.equals(copies.reversed())); + } + public static void main(String[] args) { try { List empty = Collections.nCopies(0, "foo"); checkEmpty(empty); checkEmpty(empty.subList(0,0)); @@ -156,10 +167,12 @@ checkEquals(); checkReversed(); + checkValueCopies(); + } catch (Throwable t) { unexpected(t); } System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed); if (failed > 0) throw new Error("Some tests failed"); }