onami-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From as...@apache.org
Subject svn commit: r1610114 - in /onami/trunk: lifecycle/core/src/main/java/org/apache/onami/lifecycle/core/ logging/core/src/main/java/org/apache/onami/logging/core/ test/src/main/java/org/apache/onami/test/ test/src/main/java/org/apache/onami/test/mock/guice/
Date Sun, 13 Jul 2014 05:35:28 GMT
Author: ash2k
Date: Sun Jul 13 05:35:27 2014
New Revision: 1610114

URL: http://svn.apache.org/r1610114
Log:
ONAMI-112 call setAccessible() inside doPrivileged()

Modified:
    onami/trunk/lifecycle/core/src/main/java/org/apache/onami/lifecycle/core/StageableMethod.java
    onami/trunk/logging/core/src/main/java/org/apache/onami/logging/core/AbstractLoggerInjector.java
    onami/trunk/test/src/main/java/org/apache/onami/test/OnamiRunner.java
    onami/trunk/test/src/main/java/org/apache/onami/test/OnamiSuite.java
    onami/trunk/test/src/main/java/org/apache/onami/test/mock/guice/MockMembersInjector.java

Modified: onami/trunk/lifecycle/core/src/main/java/org/apache/onami/lifecycle/core/StageableMethod.java
URL: http://svn.apache.org/viewvc/onami/trunk/lifecycle/core/src/main/java/org/apache/onami/lifecycle/core/StageableMethod.java?rev=1610114&r1=1610113&r2=1610114&view=diff
==============================================================================
--- onami/trunk/lifecycle/core/src/main/java/org/apache/onami/lifecycle/core/StageableMethod.java
(original)
+++ onami/trunk/lifecycle/core/src/main/java/org/apache/onami/lifecycle/core/StageableMethod.java
Sun Jul 13 05:35:27 2014
@@ -21,6 +21,8 @@ package org.apache.onami.lifecycle.core;
 
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 
 /**
  * A {@link StageableMethod} is a reference to a stageable injectee
@@ -55,10 +57,17 @@ final class StageableMethod
     {
         try
         {
-            if ( !stageMethod.isAccessible() )
+            AccessController.doPrivileged( new PrivilegedAction<Void>()
             {
-                stageMethod.setAccessible( true );
-            }
+
+                @Override
+                public Void run()
+                {
+                    stageMethod.setAccessible( true );
+                    return null;
+                }
+
+            } );
             stageMethod.invoke( object );
         }
         catch ( InvocationTargetException e )

Modified: onami/trunk/logging/core/src/main/java/org/apache/onami/logging/core/AbstractLoggerInjector.java
URL: http://svn.apache.org/viewvc/onami/trunk/logging/core/src/main/java/org/apache/onami/logging/core/AbstractLoggerInjector.java?rev=1610114&r1=1610113&r2=1610114&view=diff
==============================================================================
--- onami/trunk/logging/core/src/main/java/org/apache/onami/logging/core/AbstractLoggerInjector.java
(original)
+++ onami/trunk/logging/core/src/main/java/org/apache/onami/logging/core/AbstractLoggerInjector.java
Sun Jul 13 05:35:27 2014
@@ -23,6 +23,8 @@ import static java.lang.String.format;
 import static java.lang.reflect.Modifier.isFinal;
 
 import java.lang.reflect.Field;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 
 import com.google.inject.MembersInjector;
 import com.google.inject.ProvisionException;
@@ -45,10 +47,19 @@ public abstract class AbstractLoggerInje
      *
      * @param field the logger field has to be injected.
      */
-    public AbstractLoggerInjector( Field field )
+    public AbstractLoggerInjector( final Field field )
     {
         this.field = field;
-        this.field.setAccessible(true);
+        AccessController.doPrivileged( new PrivilegedAction<Void>()
+        {
+
+            public Void run()
+            {
+                field.setAccessible( true );
+                return null;
+            }
+
+        } );
     }
 
     /**

Modified: onami/trunk/test/src/main/java/org/apache/onami/test/OnamiRunner.java
URL: http://svn.apache.org/viewvc/onami/trunk/test/src/main/java/org/apache/onami/test/OnamiRunner.java?rev=1610114&r1=1610113&r2=1610114&view=diff
==============================================================================
--- onami/trunk/test/src/main/java/org/apache/onami/test/OnamiRunner.java (original)
+++ onami/trunk/test/src/main/java/org/apache/onami/test/OnamiRunner.java Sun Jul 13 05:35:27
2014
@@ -21,6 +21,8 @@ package org.apache.onami.test;
 
 import java.lang.reflect.Field;
 import java.lang.reflect.Modifier;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.LinkedList;
@@ -456,7 +458,16 @@ public class OnamiRunner
                             LOGGER.finer( "   inject static mock field: " + field.getName()
);
                         }
 
-                        field.setAccessible( true );
+                        AccessController.doPrivileged( new PrivilegedAction<Void>()
+                        {
+
+                            public Void run()
+                            {
+                                field.setAccessible( true );
+                                return null;
+                            }
+
+                        } );
                         field.set( field.getDeclaringClass(), mock );
                     }
                 }

Modified: onami/trunk/test/src/main/java/org/apache/onami/test/OnamiSuite.java
URL: http://svn.apache.org/viewvc/onami/trunk/test/src/main/java/org/apache/onami/test/OnamiSuite.java?rev=1610114&r1=1610113&r2=1610114&view=diff
==============================================================================
--- onami/trunk/test/src/main/java/org/apache/onami/test/OnamiSuite.java (original)
+++ onami/trunk/test/src/main/java/org/apache/onami/test/OnamiSuite.java Sun Jul 13 05:35:27
2014
@@ -21,6 +21,8 @@ package org.apache.onami.test;
 
 import java.lang.reflect.Field;
 import java.lang.reflect.Modifier;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.LinkedList;
@@ -414,7 +416,16 @@ public class OnamiSuite
                             LOGGER.finer( "   inject static mock field: " + field.getName()
);
                         }
 
-                        field.setAccessible( true );
+                        AccessController.doPrivileged( new PrivilegedAction<Void>()
+                        {
+
+                            public Void run()
+                            {
+                                field.setAccessible( true );
+                                return null;
+                            }
+
+                        } );
                         field.set( field.getDeclaringClass(), mock );
                     }
                 }

Modified: onami/trunk/test/src/main/java/org/apache/onami/test/mock/guice/MockMembersInjector.java
URL: http://svn.apache.org/viewvc/onami/trunk/test/src/main/java/org/apache/onami/test/mock/guice/MockMembersInjector.java?rev=1610114&r1=1610113&r2=1610114&view=diff
==============================================================================
--- onami/trunk/test/src/main/java/org/apache/onami/test/mock/guice/MockMembersInjector.java
(original)
+++ onami/trunk/test/src/main/java/org/apache/onami/test/mock/guice/MockMembersInjector.java
Sun Jul 13 05:35:27 2014
@@ -20,6 +20,8 @@ package org.apache.onami.test.mock.guice
  */
 
 import java.lang.reflect.Field;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 import java.util.Map;
 
 import com.google.inject.MembersInjector;
@@ -43,10 +45,20 @@ public class MockMembersInjector<T>
      * @param field the field that has to be injected.
      * @param mockedObjects  the map of mocked object.
      */
-    public MockMembersInjector( Field field, Map<Field, Object> mockedObjects )
+    public MockMembersInjector( final Field field, Map<Field, Object> mockedObjects
)
     {
         this.field = field;
         this.mockedObjects = mockedObjects;
+        AccessController.doPrivileged( new PrivilegedAction<Void>()
+        {
+
+            public Void run()
+            {
+                field.setAccessible( true );
+                return null;
+            }
+
+        } );
     }
 
     /**
@@ -54,9 +66,6 @@ public class MockMembersInjector<T>
      */
     public void injectMembers( T t )
     {
-        boolean wasAccessible = field.isAccessible();
-        field.setAccessible( true );
-
         try
         {
             field.set( t, mockedObjects.get( field ) );
@@ -65,10 +74,6 @@ public class MockMembersInjector<T>
         {
             throw new RuntimeException( e );
         }
-        finally
-        {
-            field.setAccessible( wasAccessible );
-        }
     }
 
 }



Mime
View raw message