blob: 005f65effa12ab42d2c244be3e05c7a45519ba97 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2007 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 6569218
27 * @summary Specification of some BasicPermission method does not fit with implementation
28 */
29
30import java.security.BasicPermission;
31
32public class ExitVMEquals {
33 public static void main(String[] args) throws Exception {
34 BasicPermission bp1 = new BP("exitVM");
35 BasicPermission bp2 = new BP("exitVM.*");
36
37 StringBuffer sb = new StringBuffer();
38
39 // First, make sure the old restrictions on exitVM and exitVM.* still hold.
40 if (!bp1.implies(bp2)) sb.append("bp1 does not implies bp2\n");
41 if (!bp2.implies(bp1)) sb.append("bp2 does not implies bp1\n");
42
43 // Test against hashCode spec
44 if (bp1.hashCode() != bp1.getName().hashCode())
45 sb.append("bp1 hashCode not spec consistent\n");
46 if (bp2.hashCode() != bp2.getName().hashCode())
47 sb.append("bp2 hashCode not spec consistent\n");
48
49 // Test against equals spec
50 if (bp1.getName().equals(bp2.getName())) {
51 if (!bp1.equals(bp2)) {
52 sb.append("BP breaks equals spec\n");
53 }
54 }
55 if (!bp1.getName().equals(bp2.getName())) {
56 if (bp1.equals(bp2)) {
57 sb.append("BP breaks equals spec in another way\n");
58 }
59 }
60
61 // Tests against common knowledge: If equals, then hashCode should be same
62 if (bp1.equals(bp2)) {
63 if (bp1.hashCode() != bp2.hashCode()) {
64 sb.append("Equal objects have unequal hashCode?\n");
65 }
66 }
67
68 if (sb.length() > 0) {
69 throw new Exception(sb.toString());
70 }
71 }
72}
73
74class BP extends BasicPermission {
75 BP(String name) {
76 super(name);
77 }
78}