blob: e749ffe94206d396979aa51627f7ae7a65cd1858 [file] [log] [blame]
okutsu540e6092013-07-19 12:14:34 +09001/*
2 * Copyright (c) 2013, 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. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26/*
27 * @test
28 * @bug 8001029
29 * @summary Make sure that TimeZone.setDefault throws a SecurityException if the
30 * security manager doesn't permit.
31 * @run main/othervm SetDefaultSecurityTest
32 */
33
34import java.util.SimpleTimeZone;
35import java.util.TimeZone;
36
37public class SetDefaultSecurityTest {
38 static final TimeZone NOWHERE = new SimpleTimeZone(Integer.MAX_VALUE, "Nowhere");
39
40 public static void main(String[] args) {
41 TimeZone defaultZone = TimeZone.getDefault();
42
43 // Make sure that TimeZone.setDefault works for trusted code
44 TimeZone.setDefault(NOWHERE);
45 if (!NOWHERE.equals(TimeZone.getDefault())) {
46 new RuntimeException("TimeZone.setDefault doesn't work for trusted code.");
47 }
48 // Restore defaultZone
49 TimeZone.setDefault(defaultZone);
50 if (!defaultZone.equals(TimeZone.getDefault())) {
51 new RuntimeException("TimeZone.setDefault doesn't restore defaultZone.");
52 }
53
54 // Install a SecurityManager.
55 System.setSecurityManager(new SecurityManager());
56 try {
57 TimeZone.setDefault(NOWHERE);
58 throw new RuntimeException("TimeZone.setDefault doesn't throw a SecurityException.");
59 } catch (SecurityException se) {
60 // OK
61 }
62 TimeZone tz = TimeZone.getDefault();
63 if (!defaultZone.equals(tz)) {
64 throw new RuntimeException("Default TimeZone changed: " + tz);
65 }
66 }
67}