2783N/A/*
2783N/A * Copyright (c) 1998, Oracle and/or its affiliates. All rights reserved.
2783N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2783N/A *
2783N/A * This code is free software; you can redistribute it and/or modify it
2783N/A * under the terms of the GNU General Public License version 2 only, as
2783N/A * published by the Free Software Foundation.
2783N/A *
2783N/A * This code is distributed in the hope that it will be useful, but WITHOUT
2783N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2783N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2783N/A * version 2 for more details (a copy is included in the LICENSE file that
2783N/A * accompanied this code).
2783N/A *
2783N/A * You should have received a copy of the GNU General Public License version
2783N/A * 2 along with this work; if not, write to the Free Software Foundation,
2783N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2783N/A *
2783N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2783N/A * or visit www.oracle.com if you need additional information or have any
2783N/A * questions.
2783N/A */
2783N/A
2783N/A/* @test
2783N/A * @bug 4100814
2783N/A * @summary Make sure you can't create an array of dimension > 256.
2783N/A */
2783N/A
2783N/Aimport java.lang.reflect.Array;
2783N/A
2783N/Apublic class ExceedMaxDim {
2783N/A
2783N/A public static void main(String[] args) throws Exception {
2783N/A newInstanceOne();
2783N/A newInstanceMulti();
2783N/A zeroDimension();
2783N/A }
2783N/A
2783N/A private static void newInstanceOne() throws Exception {
2783N/A Object o = getArrayOf256Dimensions();
2783N/A try {
2783N/A o = Array.newInstance(o.getClass(), 1);
3306N/A } catch (IllegalArgumentException iae) {
2783N/A System.out.println("success: newInstanceOne test");
2783N/A return;
2783N/A }
2783N/A throw new Exception("NewArray allowed dimensions > MAXDIM");
3306N/A }
3306N/A
2783N/A private static void newInstanceMulti() throws Exception {
2783N/A Object o = getArrayOf256Dimensions();
2783N/A try {
2783N/A o = Array.newInstance(o.getClass(), new int[] { 1, 1 });
2783N/A o = Array.newInstance(o.getClass(), new int[] { 1 });
2783N/A } catch (IllegalArgumentException iae) {
2783N/A System.out.println("success: newInstanceMulti test");
2783N/A return;
2783N/A }
2783N/A throw new Exception("MultiNewArray allowed dimensions > MAXDIM");
2783N/A }
2783N/A
2783N/A private static void zeroDimension() throws Exception {
2783N/A try {
2783N/A Array.newInstance(Integer.TYPE, new int[0]);
2783N/A } catch (IllegalArgumentException iae) {
2783N/A System.out.println("success: zeroDimension test");
2783N/A return;
3306N/A }
2783N/A throw new Exception("MultiNewArray allowed dimension == 0");
2783N/A }
2783N/A
3306N/A private static Object getArrayOf256Dimensions() {
3306N/A /* 1 dimension */
2783N/A Object o = Array.newInstance(Integer.TYPE, 0);
2783N/A
2783N/A /* 254 more dimension. */
3306N/A for (int i = 1; i <= 254; i++) {
3306N/A o = Array.newInstance(o.getClass(), 1);
3306N/A }
3306N/A
3306N/A /* 255 in all. */
3306N/A return o;
3306N/A }
3306N/A}
3306N/A