< prev index next >

test/jdk/java/util/concurrent/atomic/AtomicUpdaters.java

Print this page
rev 47439 : 8189291: Test policy should extend the default system policy
Reviewed-by:
   1 /*
   2  * Copyright (c) 2012, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 7103570
  27  * @author David Holmes
  28  * @run main/othervm AtomicUpdaters
  29  * @run main/othervm AtomicUpdaters UseSM
  30  * @summary Checks the (in)ability to create field updaters for differently
  31  *          accessible fields in different locations with/without a security
  32  *          manager
  33  */
  34 
  35 import java.lang.reflect.Field;
  36 import java.security.AccessControlException;
  37 import java.security.CodeSource;
  38 import java.security.Permission;
  39 import java.security.PermissionCollection;
  40 import java.security.Policy;
  41 import java.security.ProtectionDomain;
  42 import java.util.concurrent.atomic.AtomicInteger;
  43 import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
  44 import java.util.concurrent.atomic.AtomicLong;
  45 import java.util.concurrent.atomic.AtomicLongFieldUpdater;
  46 import java.util.concurrent.atomic.AtomicReference;
  47 import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
  48 
  49 public class  AtomicUpdaters {


  50     enum TYPE { INT, LONG, REF }
  51 
  52     static class Config {
  53         final Class<?> clazz;
  54         final String field;
  55         final String access;
  56         final boolean reflectOk;
  57         final boolean updaterOk;
  58         final String desc;
  59         final TYPE type;
  60 
  61         Config(Class<?> clazz, String field, String access,
  62                boolean reflectOk, boolean updaterOk, String desc, TYPE type) {
  63             this.clazz = clazz;
  64             this.field = field;
  65             this.access = access;
  66             this.reflectOk = reflectOk;
  67             this.updaterOk = updaterOk;
  68             this.desc = desc;
  69             this.type =type;


 199             throw new Error("Some tests failed - see previous stacktraces");
 200         }
 201     }
 202 
 203     /**
 204      * Policy with no permissions.
 205      */
 206     private static class NoPermissionsPolicy extends Policy {
 207         @Override
 208         public PermissionCollection getPermissions(CodeSource cs) {
 209             return Policy.UNSUPPORTED_EMPTY_COLLECTION;
 210         }
 211 
 212         @Override
 213         public PermissionCollection getPermissions(ProtectionDomain pd) {
 214             return Policy.UNSUPPORTED_EMPTY_COLLECTION;
 215         }
 216 
 217         @Override
 218         public boolean implies(ProtectionDomain pd, Permission p) {
 219             return Policy.UNSUPPORTED_EMPTY_COLLECTION.implies(p);

 220         }
 221     }
 222 }
   1 /*
   2  * Copyright (c) 2012, 2017, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 7103570 8189291
  27  * @author David Holmes
  28  * @run main/othervm AtomicUpdaters
  29  * @run main/othervm AtomicUpdaters UseSM
  30  * @summary Checks the (in)ability to create field updaters for differently
  31  *          accessible fields in different locations with/without a security
  32  *          manager
  33  */
  34 
  35 import java.lang.reflect.Field;
  36 import java.security.AccessControlException;
  37 import java.security.CodeSource;
  38 import java.security.Permission;
  39 import java.security.PermissionCollection;
  40 import java.security.Policy;
  41 import java.security.ProtectionDomain;
  42 import java.util.concurrent.atomic.AtomicInteger;
  43 import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
  44 import java.util.concurrent.atomic.AtomicLong;
  45 import java.util.concurrent.atomic.AtomicLongFieldUpdater;
  46 import java.util.concurrent.atomic.AtomicReference;
  47 import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
  48 
  49 public class  AtomicUpdaters {
  50     static final Policy DEFAULT_POLICY = Policy.getPolicy();
  51 
  52     enum TYPE { INT, LONG, REF }
  53 
  54     static class Config {
  55         final Class<?> clazz;
  56         final String field;
  57         final String access;
  58         final boolean reflectOk;
  59         final boolean updaterOk;
  60         final String desc;
  61         final TYPE type;
  62 
  63         Config(Class<?> clazz, String field, String access,
  64                boolean reflectOk, boolean updaterOk, String desc, TYPE type) {
  65             this.clazz = clazz;
  66             this.field = field;
  67             this.access = access;
  68             this.reflectOk = reflectOk;
  69             this.updaterOk = updaterOk;
  70             this.desc = desc;
  71             this.type =type;


 201             throw new Error("Some tests failed - see previous stacktraces");
 202         }
 203     }
 204 
 205     /**
 206      * Policy with no permissions.
 207      */
 208     private static class NoPermissionsPolicy extends Policy {
 209         @Override
 210         public PermissionCollection getPermissions(CodeSource cs) {
 211             return Policy.UNSUPPORTED_EMPTY_COLLECTION;
 212         }
 213 
 214         @Override
 215         public PermissionCollection getPermissions(ProtectionDomain pd) {
 216             return Policy.UNSUPPORTED_EMPTY_COLLECTION;
 217         }
 218 
 219         @Override
 220         public boolean implies(ProtectionDomain pd, Permission p) {
 221             return Policy.UNSUPPORTED_EMPTY_COLLECTION.implies(p) ||
 222                     DEFAULT_POLICY.implies(pd, p);
 223         }
 224     }
 225 }
< prev index next >