Exceptions.java revision 2362
869N/A/*
869N/A * Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
869N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
869N/A *
869N/A * This code is free software; you can redistribute it and/or modify it
869N/A * under the terms of the GNU General Public License version 2 only, as
869N/A * published by the Free Software Foundation.
869N/A *
869N/A * This code is distributed in the hope that it will be useful, but WITHOUT
869N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
869N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
869N/A * version 2 for more details (a copy is included in the LICENSE file that
869N/A * accompanied this code).
869N/A *
869N/A * You should have received a copy of the GNU General Public License version
869N/A * 2 along with this work; if not, write to the Free Software Foundation,
869N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
873N/A *
869N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
869N/A * or visit www.oracle.com if you need additional information or have any
869N/A * questions.
869N/A */
869N/A
869N/A/**
869N/A * @test
0N/A * @bug 5002910
0N/A */
0N/A
0N/Aimport java.lang.reflect.ReflectPermission;
869N/A
0N/Apublic class Exceptions {
0N/A private static int fail = 0;
0N/A private static int pass = 0;
869N/A
0N/A private static Throwable first;
869N/A
0N/A static void pass() {
869N/A pass++;
869N/A }
869N/A
0N/A static void fail(String fs, Throwable ex) {
869N/A String s = "'" + fs + "': " + ex.getClass().getName() + " thrown";
48N/A if (first == null)
869N/A first = ex;
0N/A System.err.println("FAILED: " + s);
869N/A fail++;
716N/A }
869N/A
0N/A public static void main(String [] args) {
0N/A RuntimeException re = new RuntimeException("no exception thrown");
869N/A try {
868N/A new ReflectPermission(null);
983N/A fail("null", re);
1004N/A } catch (NullPointerException x) {
1007N/A pass();
1378N/A } catch (Exception x) {
1411N/A fail("null", x);
1378N/A }
869N/A try {
869N/A new ReflectPermission("");
1004N/A fail("\"\"", re);
0N/A } catch (IllegalArgumentException x) {
0N/A pass();
869N/A } catch (Exception x) {
868N/A fail("\"\"", x);
0N/A }
0N/A
65N/A try {
869N/A new ReflectPermission(null, null);
868N/A fail("null, null", re);
65N/A } catch (NullPointerException x) {
869N/A pass();
65N/A } catch (Exception x) {
65N/A fail("null, null", x);
65N/A }
65N/A try {
65N/A new ReflectPermission("", null);
65N/A fail("\"\", null", re);
65N/A } catch (IllegalArgumentException x) {
65N/A pass();
65N/A } catch (Exception x) {
65N/A fail("\"\", null", x);
65N/A }
65N/A
65N/A if (fail != 0)
65N/A throw new RuntimeException((fail + pass) + " tests: "
65N/A + fail + " failure(s), first", first);
0N/A else
869N/A System.out.println("all " + (fail + pass) + " tests passed");
868N/A
0N/A }
0N/A}
0N/A