J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 1999 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 21 | * have any questions. |
| 22 | */ |
| 23 | |
| 24 | /* |
| 25 | * @test |
| 26 | * @bug 4240252 |
| 27 | * @summary Make sure BasicPermission constructor raises |
| 28 | * NullPointerException if permission name is null, and |
| 29 | * IllegalArgumentException is permission name is empty. |
| 30 | */ |
| 31 | |
| 32 | public class NullOrEmptyName { |
| 33 | |
| 34 | public static void main(String[]args) throws Exception { |
| 35 | NullOrEmptyName noe = new NullOrEmptyName(); |
| 36 | |
| 37 | // run without sm installed |
| 38 | noe.run(); |
| 39 | |
| 40 | // run with sm installed |
| 41 | SecurityManager sm = new SecurityManager(); |
| 42 | System.setSecurityManager(sm); |
| 43 | noe.run(); |
| 44 | |
| 45 | try { |
| 46 | // called by System.getProperty() |
| 47 | sm.checkPropertyAccess(null); |
| 48 | throw new Exception("Expected NullPointerException not thrown"); |
| 49 | } catch (NullPointerException npe) { |
| 50 | // expected exception thrown |
| 51 | } |
| 52 | |
| 53 | try { |
| 54 | // called by System.getProperty() |
| 55 | sm.checkPropertyAccess(""); |
| 56 | throw new Exception("Expected IllegalArgumentException not " + |
| 57 | "thrown"); |
| 58 | } catch (IllegalArgumentException iae) { |
| 59 | // expected exception thrown |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | void run() throws Exception { |
| 64 | |
| 65 | try { |
| 66 | System.getProperty(null); |
| 67 | throw new Exception("Expected NullPointerException not " + |
| 68 | "thrown"); |
| 69 | } catch (NullPointerException npe) { |
| 70 | // expected exception thrown |
| 71 | } |
| 72 | |
| 73 | try { |
| 74 | System.getProperty(null, "value"); |
| 75 | throw new Exception("Expected NullPointerException not " + |
| 76 | "thrown"); |
| 77 | } catch (NullPointerException npe) { |
| 78 | // expected exception thrown |
| 79 | } |
| 80 | |
| 81 | try { |
| 82 | System.getProperty(""); |
| 83 | throw new Exception("Expected IllegalArgumentException not " + |
| 84 | "thrown"); |
| 85 | } catch (IllegalArgumentException iae) { |
| 86 | // expected exception thrown |
| 87 | } |
| 88 | |
| 89 | try { |
| 90 | System.getProperty("", "value"); |
| 91 | throw new Exception("Expected IllegalArgumentException not " + |
| 92 | "thrown"); |
| 93 | } catch (IllegalArgumentException iae) { |
| 94 | // expected exception thrown |
| 95 | } |
| 96 | |
| 97 | try { |
| 98 | System.setProperty(null, "value"); |
| 99 | throw new Exception("Expected NullPointerException not " + |
| 100 | "thrown"); |
| 101 | } catch (NullPointerException npe) { |
| 102 | // expected exception thrown |
| 103 | } |
| 104 | |
| 105 | try { |
| 106 | System.setProperty("", "value"); |
| 107 | throw new Exception("Expected IllegalArgumentException not " + |
| 108 | "thrown"); |
| 109 | } catch (IllegalArgumentException iae) { |
| 110 | // expected exception thrown |
| 111 | } |
| 112 | } |
| 113 | } |