1 Reply Latest reply on Dec 9, 2009 10:03 AM by Kabir Khan

    org.jboss.util.collection.ConcurrentSkipListMap fails when r

    Kabir Khan Master

      Adding this test to common-core

      package org.jboss.test.util.test.collection;
      
      import java.util.Map;
      
      import org.jboss.util.collection.ConcurrentSkipListMap;
      
      /**
       *
       * @author <a href="kabir.khan@jboss.com">Kabir Khan</a>
       * @version $Revision: 1.1 $
       */
      public class ConcurrentSkipListMapSecureTestCase extends AbstractMapUnitTest
      {
       @Override
       protected void setUp() throws Exception
       {
       super.setUp();
       System.setSecurityManager(new SecurityManager());
       }
      
       @Override
       @SuppressWarnings("unchecked")
       protected Map createEmptyMap()
       {
       return new ConcurrentSkipListMap();
       }
      }
      


      fails with the message:
      java.lang.ExceptionInInitializerError
       at org.jboss.test.util.test.collection.ConcurrentSkipListMapSecureTestCase.createEmptyMap(ConcurrentSkipListMapSecureTestCase.java:46)
       at org.jboss.test.util.test.collection.AbstractMapUnitTest.testBasicOperations(AbstractMapUnitTest.java:21)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:597)
       at junit.framework.TestCase.runTest(TestCase.java:168)
       at junit.framework.TestCase.runBare(TestCase.java:134)
       at junit.framework.TestResult$1.protect(TestResult.java:110)
       at junit.framework.TestResult.runProtected(TestResult.java:128)
       at junit.framework.TestResult.run(TestResult.java:113)
       at junit.framework.TestCase.run(TestCase.java:124)
       at junit.framework.TestSuite.runTest(TestSuite.java:232)
       at junit.framework.TestSuite.run(TestSuite.java:227)
       at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:81)
       at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)
       at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
       at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
       at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
       at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
       at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
      Caused by: java.lang.RuntimeException: java.security.AccessControlException: access denied (java.lang.RuntimePermission accessDeclaredMembers)
       at java.util.concurrent.atomic.AtomicReferenceFieldUpdater$AtomicReferenceFieldUpdaterImpl.<init>(AtomicReferenceFieldUpdater.java:189)
       at java.util.concurrent.atomic.AtomicReferenceFieldUpdater.newUpdater(AtomicReferenceFieldUpdater.java:65)
       at org.jboss.util.collection.ConcurrentSkipListMap.<clinit>(ConcurrentSkipListMap.java:356)
       ... 21 more
      Caused by: java.security.AccessControlException: access denied (java.lang.RuntimePermission accessDeclaredMembers)
       at java.security.AccessControlContext.checkPermission(AccessControlContext.java:323)
       at java.security.AccessController.checkPermission(AccessController.java:546)
       at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
       at java.lang.SecurityManager.checkMemberAccess(SecurityManager.java:1662)
       at java.lang.Class.checkMemberAccess(Class.java:2157)
       at java.lang.Class.getDeclaredField(Class.java:1879)
       at java.util.concurrent.atomic.AtomicReferenceFieldUpdater$AtomicReferenceFieldUpdaterImpl.<init>(AtomicReferenceFieldUpdater.java:181)
       ... 23 more
      


      I have tried changing the class
      $svn diff
      Index: src/main/java/org/jboss/util/collection/ConcurrentSkipListMap.java
      ===================================================================
      --- src/main/java/org/jboss/util/collection/ConcurrentSkipListMap.java (revision 3838)
      +++ src/main/java/org/jboss/util/collection/ConcurrentSkipListMap.java (working copy)
      @@ -%ld,%ld +%ld,%ld @@
      
       package org.jboss.util.collection;
      
      +import java.security.AccessController;
      +import java.security.PrivilegedAction;
       import java.util.AbstractCollection;
       import java.util.AbstractMap;
       import java.util.AbstractSet;
      @@ -%ld,%ld +%ld,%ld @@
       /** Updater for casHead */
       private static final
       AtomicReferenceFieldUpdater<ConcurrentSkipListMap, HeadIndex>
      - headUpdater = AtomicReferenceFieldUpdater.newUpdater
      - (ConcurrentSkipListMap.class, HeadIndex.class, "head");
      -
      + headUpdater;
      +
      + static
      + {
      + headUpdater = AccessController.doPrivileged(new PrivilegedAction<AtomicReferenceFieldUpdater<ConcurrentSkipListMap, HeadIndex>>()
      + {
      +
      + public AtomicReferenceFieldUpdater<ConcurrentSkipListMap, HeadIndex> run()
      + {
      + return AtomicReferenceFieldUpdater.newUpdater
      + (ConcurrentSkipListMap.class, HeadIndex.class, "head");
      + }
      + });
      + }
       /**
       * compareAndSet head node
       */
      

      but that still fails with the message
      java.lang.ExceptionInInitializerError
       at org.jboss.test.util.test.collection.ConcurrentSkipListMapSecureTestCase.createEmptyMap(ConcurrentSkipListMapSecureTestCase.java:46)
       at org.jboss.test.util.test.collection.AbstractMapUnitTest.testBasicOperations(AbstractMapUnitTest.java:21)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:597)
       at junit.framework.TestCase.runTest(TestCase.java:168)
       at junit.framework.TestCase.runBare(TestCase.java:134)
       at junit.framework.TestResult$1.protect(TestResult.java:110)
       at junit.framework.TestResult.runProtected(TestResult.java:128)
       at junit.framework.TestResult.run(TestResult.java:113)
       at junit.framework.TestCase.run(TestCase.java:124)
       at junit.framework.TestSuite.runTest(TestSuite.java:232)
       at junit.framework.TestSuite.run(TestSuite.java:227)
       at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:81)
       at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)
       at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
       at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
       at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
       at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
       at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
      Caused by: java.lang.RuntimeException: java.security.AccessControlException: access denied (java.lang.RuntimePermission accessDeclaredMembers)
       at java.util.concurrent.atomic.AtomicReferenceFieldUpdater$AtomicReferenceFieldUpdaterImpl.<init>(AtomicReferenceFieldUpdater.java:189)
       at java.util.concurrent.atomic.AtomicReferenceFieldUpdater.newUpdater(AtomicReferenceFieldUpdater.java:65)
       at org.jboss.util.collection.ConcurrentSkipListMap$1.run(ConcurrentSkipListMap.java:367)
       at org.jboss.util.collection.ConcurrentSkipListMap$1.run(ConcurrentSkipListMap.java:1)
       at java.security.AccessController.doPrivileged(Native Method)
       at org.jboss.util.collection.ConcurrentSkipListMap.<clinit>(ConcurrentSkipListMap.java:362)
       ... 21 more
      Caused by: java.security.AccessControlException: access denied (java.lang.RuntimePermission accessDeclaredMembers)
       at java.security.AccessControlContext.checkPermission(AccessControlContext.java:323)
       at java.security.AccessController.checkPermission(AccessController.java:546)
       at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
       at java.lang.SecurityManager.checkMemberAccess(SecurityManager.java:1662)
       at java.lang.Class.checkMemberAccess(Class.java:2157)
       at java.lang.Class.getDeclaredField(Class.java:1879)
       at java.util.concurrent.atomic.AtomicReferenceFieldUpdater$AtomicReferenceFieldUpdaterImpl.<init>(AtomicReferenceFieldUpdater.java:181)
       ... 26 more
      

      Probably because the privileged block is not is the same jar as the AtomicReferenceFieldUpdater?