Path: blob/master/test/jdk/java/util/Arrays/Fill.java
41149 views
/*1* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 422989226* @summary Arrays.fill(Object[], ...) should throw ArrayStoreException27* @author Martin Buchholz28*/2930import java.io.*;31import java.util.*;32import java.util.concurrent.*;33import java.util.concurrent.atomic.*;3435public class Fill {36private static void realMain(String[] args) throws Throwable {37try {38Arrays.fill(new Integer[3], "foo");39fail("Expected ArrayStoreException");40}41catch (ArrayStoreException e) { pass(); }42catch (Throwable t) { unexpected(t); }4344try {45Arrays.fill(new Integer[3], 0, 2, "foo");46fail("Expected ArrayStoreException");47}48catch (ArrayStoreException e) { pass(); }49catch (Throwable t) { unexpected(t); }5051try {52Arrays.fill(new Integer[3], 0, 4, "foo");53fail("Expected ArrayIndexOutOfBoundsException");54}55catch (ArrayIndexOutOfBoundsException e) { pass(); }56catch (Throwable t) { unexpected(t); }57}5859//--------------------- Infrastructure ---------------------------60static volatile int passed = 0, failed = 0;61static void pass() {passed++;}62static void fail() {failed++; Thread.dumpStack();}63static void fail(String msg) {System.out.println(msg); fail();}64static void unexpected(Throwable t) {failed++; t.printStackTrace();}65static void check(boolean cond) {if (cond) pass(); else fail();}66static void equal(Object x, Object y) {67if (x == null ? y == null : x.equals(y)) pass();68else fail(x + " not equal to " + y);}69public static void main(String[] args) throws Throwable {70try {realMain(args);} catch (Throwable t) {unexpected(t);}71System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);72if (failed > 0) throw new AssertionError("Some tests failed");}73}747576