Repository: incubator-tamaya
Updated Branches:
  refs/heads/master 39e96d29f -> c82940e2f


TAMAYA-53 Setting a non public field via reflection should be done in a 
privileged block.


Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/c82940e2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/c82940e2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/c82940e2

Branch: refs/heads/master
Commit: c82940e2ff8f52cb17180ace059aff1fc87a313a
Parents: 39e96d2
Author: Oliver B. Fischer <[email protected]>
Authored: Mon Feb 9 08:51:47 2015 +0100
Committer: Oliver B. Fischer <[email protected]>
Committed: Mon Feb 9 08:51:47 2015 +0100

----------------------------------------------------------------------
 .../resources/findbugs/findbugs-exclude.xml     |  3 ---
 .../tamaya/inject/internal/ConfiguredField.java | 26 ++++++++++++++------
 2 files changed, 18 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c82940e2/buildconfigurations/src/main/resources/findbugs/findbugs-exclude.xml
----------------------------------------------------------------------
diff --git 
a/buildconfigurations/src/main/resources/findbugs/findbugs-exclude.xml 
b/buildconfigurations/src/main/resources/findbugs/findbugs-exclude.xml
index 7ec44d3..7712adf 100644
--- a/buildconfigurations/src/main/resources/findbugs/findbugs-exclude.xml
+++ b/buildconfigurations/src/main/resources/findbugs/findbugs-exclude.xml
@@ -108,9 +108,6 @@ under the License.
         <Class name="org.apache.tamaya.inject.internal.ConfiguredSetterMethod" 
/>
     </Match>
     <Match>
-        <Class name="org.apache.tamaya.inject.internal.ConfiguredField" />
-    </Match>
-    <Match>
         <Class 
name="org.apache.tamaya.inject.internal.ConfigChangeCallbackMethod" />
     </Match>
     <Match>

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c82940e2/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredField.java
----------------------------------------------------------------------
diff --git 
a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredField.java
 
b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredField.java
index 2ee5aa2..f2a0869 100644
--- 
a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredField.java
+++ 
b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredField.java
@@ -19,6 +19,8 @@
 package org.apache.tamaya.inject.internal;
 
 import java.lang.reflect.Field;
+import java.security.AccessController;
+import java.security.PrivilegedExceptionAction;
 import java.util.List;
 import java.util.Objects;
 
@@ -38,7 +40,7 @@ public class ConfiguredField {
     /**
      * The configured field instance.
      */
-    private Field annotatedField;
+    protected Field annotatedField;
 
     /**
      * Models a configured field and provides mechanisms for injection.
@@ -73,14 +75,22 @@ public class ConfiguredField {
     public void applyValue(Object target, String configValue, boolean resolve) 
throws ConfigException {
         Objects.requireNonNull(target);
         try {
-            if (resolve && configValue != null) {
-                // net step perform exression resolution, if any
-                configValue = InjectionUtils.evaluateValue(configValue);
-            }
+            // Next step perform expression resolution, if any
+            String evaluatedValue = resolve && configValue != null
+                    ? InjectionUtils.evaluateValue(configValue)
+                    : configValue;
+
             // Check for adapter/filter
-            Object value = InjectionUtils.adaptValue(this.annotatedField, 
TypeLiteral.of(this.annotatedField.getType()), configValue);
-            annotatedField.setAccessible(true);
-            annotatedField.set(target, value);
+            Object value = InjectionUtils.adaptValue(this.annotatedField, 
TypeLiteral.of(this.annotatedField.getType()), evaluatedValue);
+
+            AccessController.doPrivileged(new 
PrivilegedExceptionAction<Object>() {
+                @Override
+                public Object run() throws Exception {
+                    annotatedField.setAccessible(true);
+                    annotatedField.set(target, value);
+                    return value;
+                }
+            });
         } catch (Exception e) {
             throw new ConfigException("Failed to annotation configured field: 
" + this.annotatedField.getDeclaringClass()
                     .getName() + '.' + annotatedField.getName(), e);

Reply via email to