Search in sources :

Example 1 with BasicPermission

use of java.security.BasicPermission in project jdk8u_jdk by JetBrains.

the class BP method main.

public static void main(String[] args) throws Exception {
    BasicPermission bp1 = new BP("exitVM");
    BasicPermission bp2 = new BP("exitVM.*");
    StringBuffer sb = new StringBuffer();
    // First, make sure the old restrictions on exitVM and exitVM.* still hold.
    if (!bp1.implies(bp2))
        sb.append("bp1 does not implies bp2\n");
    if (!bp2.implies(bp1))
        sb.append("bp2 does not implies bp1\n");
    // Test against hashCode spec
    if (bp1.hashCode() != bp1.getName().hashCode())
        sb.append("bp1 hashCode not spec consistent\n");
    if (bp2.hashCode() != bp2.getName().hashCode())
        sb.append("bp2 hashCode not spec consistent\n");
    // Test against equals spec
    if (bp1.getName().equals(bp2.getName())) {
        if (!bp1.equals(bp2)) {
            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());
    }
}
Also used : BasicPermission(java.security.BasicPermission)

Aggregations

BasicPermission (java.security.BasicPermission)1