1/* 2 * Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24/** 25 * @test 26 * @bug 5002910 27 */ 28 29import java.lang.reflect.ReflectPermission; 30 31public class Exceptions { 32 private static int fail = 0; 33 private static int pass = 0; 34 35 private static Throwable first; 36 37 static void pass() { 38 pass++; 39 } 40 41 static void fail(String fs, Throwable ex) { 42 String s = "'" + fs + "': " + ex.getClass().getName() + " thrown"; 43 if (first == null) 44 first = ex; 45 System.err.println("FAILED: " + s); 46 fail++; 47 } 48 49 public static void main(String [] args) { 50 RuntimeException re = new RuntimeException("no exception thrown"); 51 try { 52 new ReflectPermission(null); 53 fail("null", re); 54 } catch (NullPointerException x) { 55 pass(); 56 } catch (Exception x) { 57 fail("null", x); 58 } 59 try { 60 new ReflectPermission(""); 61 fail("\"\"", re); 62 } catch (IllegalArgumentException x) { 63 pass(); 64 } catch (Exception x) { 65 fail("\"\"", x); 66 } 67 68 try { 69 new ReflectPermission(null, null); 70 fail("null, null", re); 71 } catch (NullPointerException x) { 72 pass(); 73 } catch (Exception x) { 74 fail("null, null", x); 75 } 76 try { 77 new ReflectPermission("", null); 78 fail("\"\", null", re); 79 } catch (IllegalArgumentException x) { 80 pass(); 81 } catch (Exception x) { 82 fail("\"\", null", x); 83 } 84 85 if (fail != 0) 86 throw new RuntimeException((fail + pass) + " tests: " 87 + fail + " failure(s), first", first); 88 else 89 System.out.println("all " + (fail + pass) + " tests passed"); 90 91 } 92} 93