Path: blob/master/test/jdk/java/security/BasicPermission/ExitVMEquals.java
41149 views
/*1* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 656921826* @summary Specification of some BasicPermission method does not fit with implementation27*/2829import java.security.BasicPermission;3031public class ExitVMEquals {32public static void main(String[] args) throws Exception {33BasicPermission bp1 = new BP("exitVM");34BasicPermission bp2 = new BP("exitVM.*");3536StringBuffer sb = new StringBuffer();3738// First, make sure the old restrictions on exitVM and exitVM.* still hold.39if (!bp1.implies(bp2)) sb.append("bp1 does not implies bp2\n");40if (!bp2.implies(bp1)) sb.append("bp2 does not implies bp1\n");4142// Test against hashCode spec43if (bp1.hashCode() != bp1.getName().hashCode())44sb.append("bp1 hashCode not spec consistent\n");45if (bp2.hashCode() != bp2.getName().hashCode())46sb.append("bp2 hashCode not spec consistent\n");4748// Test against equals spec49if (bp1.getName().equals(bp2.getName())) {50if (!bp1.equals(bp2)) {51sb.append("BP breaks equals spec\n");52}53}54if (!bp1.getName().equals(bp2.getName())) {55if (bp1.equals(bp2)) {56sb.append("BP breaks equals spec in another way\n");57}58}5960// Tests against common knowledge: If equals, then hashCode should be same61if (bp1.equals(bp2)) {62if (bp1.hashCode() != bp2.hashCode()) {63sb.append("Equal objects have unequal hashCode?\n");64}65}6667if (sb.length() > 0) {68throw new Exception(sb.toString());69}70}71}7273class BP extends BasicPermission {74BP(String name) {75super(name);76}77}787980