test/jdk/java/security/Permission/ToString.java
author pli
Tue, 16 Jul 2019 00:57:00 +0000
changeset 55689 8c5c9d86e1d6
parent 47216 71c04702a3d5
permissions -rw-r--r--
8227512: [TESTBUG] Fix JTReg javac test failures with Graal Reviewed-by: mcimadamore
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2172
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2172
diff changeset
     2
 * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
2172
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
     4
 *
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
     7
 * published by the Free Software Foundation.
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
     8
 *
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    13
 * accompanied this code).
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    14
 *
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2172
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2172
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2172
diff changeset
    21
 * questions.
2172
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    22
 */
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    23
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    24
/*
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    25
 * @test
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    26
 * @bug 6549506
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    27
 * @summary Specification of Permission.toString() method contradicts with
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    28
 *      JDK implementation
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    29
 */
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    30
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    31
import java.security.*;
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    32
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    33
public class ToString {
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    34
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    35
    public static void main(String[]args) throws Exception {
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    36
        DummyWritePermission dummyPerm = new DummyWritePermission();
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    37
        NullActionPermission nullActionPerm = new NullActionPermission();
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    38
        System.out.println(dummyPerm.toString());
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    39
        System.out.println(dummyPerm.getDescription());
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    40
        System.out.println(nullActionPerm.toString());
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    41
        System.out.println(nullActionPerm.getDescription());
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    42
        if (!dummyPerm.toString().equals(dummyPerm.getDescription())) {
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    43
            throw new Exception("The expected permission.toString() is " +
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    44
                dummyPerm.getDescription() + ", but " +
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    45
                dummyPerm.toString() + " returned!");
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    46
        }
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    47
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    48
        if (!nullActionPerm.toString().equals(nullActionPerm.getDescription())) {
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    49
            throw new Exception("The expected permission.toString() is " +
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    50
                nullActionPerm.getDescription() + ", but " +
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    51
                nullActionPerm.toString() + " returned!");
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    52
        }
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    53
    }
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    54
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    55
    private static abstract class SimplePermission extends Permission {
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    56
        public SimplePermission(String name) {
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    57
            super(name);
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    58
        }
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    59
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    60
        public boolean implies(Permission permission) {
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    61
            return false;
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    62
        }
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    63
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    64
        public boolean equals(Object obj) {
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    65
            return false;
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    66
        }
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    67
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    68
        public int hashCode() {
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    69
            return 13;
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    70
        }
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    71
    }
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    72
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    73
    private static class DummyWritePermission extends SimplePermission {
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    74
        public DummyWritePermission() {
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    75
            super("permit to");
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    76
        }
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    77
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    78
        public String getActions() {
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    79
            return "write";
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    80
        }
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    81
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    82
        public String getDescription() {
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    83
            return "(\"ToString$DummyWritePermission\" \"permit to\" \"write\")";
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    84
        }
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    85
    }
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    86
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    87
    private static class NullActionPermission extends SimplePermission {
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    88
        public NullActionPermission() {
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    89
            super("permit to");
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    90
        }
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    91
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    92
        public String getActions() {
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    93
            return null;
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    94
        }
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    95
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    96
        public String getDescription() {
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    97
            return "(\"ToString$NullActionPermission\" \"permit to\")";
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    98
        }
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
    99
    }
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
   100
2e7377d894db 6549506: Specification of Permission.toString() method contradicts with JDK implementation
xuelei
parents:
diff changeset
   101
}