Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/lang/reflect/ReflectPermission/Exceptions.java
38828 views
/*1* Copyright (c) 2004, 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 500291026*/2728import java.lang.reflect.ReflectPermission;2930public class Exceptions {31private static int fail = 0;32private static int pass = 0;3334private static Throwable first;3536static void pass() {37pass++;38}3940static void fail(String fs, Throwable ex) {41String s = "'" + fs + "': " + ex.getClass().getName() + " thrown";42if (first == null)43first = ex;44System.err.println("FAILED: " + s);45fail++;46}4748public static void main(String [] args) {49RuntimeException re = new RuntimeException("no exception thrown");50try {51new ReflectPermission(null);52fail("null", re);53} catch (NullPointerException x) {54pass();55} catch (Exception x) {56fail("null", x);57}58try {59new ReflectPermission("");60fail("\"\"", re);61} catch (IllegalArgumentException x) {62pass();63} catch (Exception x) {64fail("\"\"", x);65}6667try {68new ReflectPermission(null, null);69fail("null, null", re);70} catch (NullPointerException x) {71pass();72} catch (Exception x) {73fail("null, null", x);74}75try {76new ReflectPermission("", null);77fail("\"\", null", re);78} catch (IllegalArgumentException x) {79pass();80} catch (Exception x) {81fail("\"\", null", x);82}8384if (fail != 0)85throw new RuntimeException((fail + pass) + " tests: "86+ fail + " failure(s), first", first);87else88System.out.println("all " + (fail + pass) + " tests passed");8990}91}929394