ExitVMEquals.java revision 0
0N/A/*
0N/A * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
0N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
0N/A * CA 95054 USA or visit www.sun.com if you need additional information or
0N/A * have any questions.
0N/A */
0N/A
0N/A/*
0N/A * @test
0N/A * @bug 6569218
0N/A * @summary Specification of some BasicPermission method does not fit with implementation
0N/A */
0N/A
288N/Aimport java.security.BasicPermission;
0N/A
0N/Apublic class ExitVMEquals {
0N/A public static void main(String[] args) throws Exception {
0N/A BasicPermission bp1 = new BP("exitVM");
0N/A BasicPermission bp2 = new BP("exitVM.*");
0N/A
0N/A StringBuffer sb = new StringBuffer();
0N/A
0N/A // First, make sure the old restrictions on exitVM and exitVM.* still hold.
0N/A if (!bp1.implies(bp2)) sb.append("bp1 does not implies bp2\n");
0N/A if (!bp2.implies(bp1)) sb.append("bp2 does not implies bp1\n");
0N/A
0N/A // Test against hashCode spec
0N/A if (bp1.hashCode() != bp1.getName().hashCode())
0N/A sb.append("bp1 hashCode not spec consistent\n");
0N/A if (bp2.hashCode() != bp2.getName().hashCode())
0N/A sb.append("bp2 hashCode not spec consistent\n");
0N/A
0N/A // Test against equals spec
0N/A if (bp1.getName().equals(bp2.getName())) {
0N/A if (!bp1.equals(bp2)) {
0N/A sb.append("BP breaks equals spec\n");
}
}
if (!bp1.getName().equals(bp2.getName())) {
if (bp1.equals(bp2)) {
sb.append("BP breaks equals spec in another way\n");
}
}
// Tests against common knowledge: If equals, then hashCode should be same
if (bp1.equals(bp2)) {
if (bp1.hashCode() != bp2.hashCode()) {
sb.append("Equal objects have unequal hashCode?\n");
}
}
if (sb.length() > 0) {
throw new Exception(sb.toString());
}
}
}
class BP extends BasicPermission {
BP(String name) {
super(name);
}
}