bval-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Romain Manni-Bucau <rmannibu...@gmail.com>
Subject Fwd: svn commit: r1628598 [1/2] - in /bval/branches/bval-11: ./ bval-core/ bval-core/src/main/java/org/apache/bval/ bval-core/src/main/java/org/apache/bval/model/ bval-core/src/main/java/org/apache/bval/util/ bval-core/src/main/java/org/apache/bval/util/ref...
Date Sat, 06 Dec 2014 08:08:32 GMT
Hi Matt,

I have 2 questions:
1) surely obvious but I dont get why you re-set the accessible (if
(mustSet)). While we need it accessible we can keep it set to true no?
2) more important: tck are broken now Tests run: 758, Failures: 13,
Errors: 0, Skipped: 0 (mvn clean install -Ptck11) :(


Romain Manni-Bucau
@rmannibucau
http://www.tomitribe.com
http://rmannibucau.wordpress.com
https://github.com/rmannibucau



---------- Forwarded message ----------
From:  <mbenson@apache.org>
Date: 2014-10-01 6:37 GMT+02:00
Subject: svn commit: r1628598 [1/2] - in /bval/branches/bval-11: ./
bval-core/ bval-core/src/main/java/org/apache/bval/
bval-core/src/main/java/org/apache/bval/model/
bval-core/src/main/java/org/apache/bval/util/
bval-core/src/main/java/org/apache/bval/util/ref...
To: commits@bval.apache.org


Author: mbenson
Date: Wed Oct  1 04:37:36 2014
New Revision: 1628598

URL: http://svn.apache.org/r1628598
Log:
use commons weaver/privilizer

Removed:
    bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/reflection/DefaultReflection.java
    bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/reflection/SecurityManagerReflection.java
Modified:
    bval/branches/bval-11/bval-core/pom.xml
    bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/ConstructorAccess.java
    bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/model/MetaBean.java
    bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/AccessStrategy.java
    bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/BValVersion.java
    bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/FieldAccess.java
    bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/IndexedAccess.java
    bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/KeyedAccess.java
    bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/MethodAccess.java
    bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/reflection/Reflection.java
    bval/branches/bval-11/bval-jsr/   (props changed)
    bval/branches/bval-11/bval-jsr/pom.xml
    bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/AnnotationConstraintBuilder.java
    bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/AnnotationProcessor.java
    bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ApacheFactoryContext.java
    bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ApacheValidationProvider.java
    bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ApacheValidatorConfiguration.java
    bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ApacheValidatorFactory.java
    bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/BeanDescriptorImpl.java
    bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ClassValidator.java
    bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ConfigurationImpl.java
    bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ConstraintAnnotationAttributes.java
    bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ConstraintDefaults.java
    bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ConstraintValidation.java
    bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/DefaultMessageInterpolator.java
    bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/DefaultValidationProviderResolver.java
    bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/JsrMetaBeanFactory.java
    bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/resolver/DefaultTraversableResolver.java
    bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/util/ClassHelper.java
    bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/xml/AnnotationProxyBuilder.java
    bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/xml/ValidationMappingParser.java
    bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/xml/ValidationParser.java
    bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/xml/ValidationParserTest.java
    bval/branches/bval-11/bval-jsr/src/test/resources/java.policy
    bval/branches/bval-11/bval-tck11/   (props changed)
    bval/branches/bval-11/bval-xstream/pom.xml
    bval/branches/bval-11/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaBeanManager.java
    bval/branches/bval-11/pom.xml

Modified: bval/branches/bval-11/bval-core/pom.xml
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-core/pom.xml?rev=1628598&r1=1628597&r2=1628598&view=diff
==============================================================================
--- bval/branches/bval-11/bval-core/pom.xml (original)
+++ bval/branches/bval-11/bval-core/pom.xml Wed Oct  1 04:37:36 2014
@@ -46,6 +46,10 @@
             <artifactId>commons-beanutils-core</artifactId>
         </dependency>
         <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-weaver-privilizer-api</artifactId>
+        </dependency>
+        <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
             <scope>test</scope>
@@ -118,6 +122,10 @@ build.timestamp=${timestamp}
                     </execution>
                 </executions>
             </plugin>
+            <plugin>
+               <groupId>org.apache.commons</groupId>
+               <artifactId>commons-weaver-maven-plugin</artifactId>
+            </plugin>
         </plugins>
         <pluginManagement>
                <plugins>

Modified: bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/ConstructorAccess.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/ConstructorAccess.java?rev=1628598&r1=1628597&r2=1628598&view=diff
==============================================================================
--- bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/ConstructorAccess.java
(original)
+++ bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/ConstructorAccess.java
Wed Oct  1 04:37:36 2014
@@ -16,13 +16,11 @@
  */
 package org.apache.bval;

-import org.apache.bval.util.AccessStrategy;
-
 import java.lang.annotation.ElementType;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Type;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
+
+import org.apache.bval.util.AccessStrategy;

 public class ConstructorAccess extends AccessStrategy {

@@ -30,18 +28,7 @@ public class ConstructorAccess extends A

     public ConstructorAccess(final Constructor<?> constructor) {
         this.constructor = constructor;
-        if (!constructor.isAccessible()) {
-            if (System.getSecurityManager() == null) {
-                constructor.setAccessible(true);
-            } else {
-                AccessController.doPrivileged(new PrivilegedAction<Void>() {
-                    public Void run() {
-                        constructor.setAccessible(true);
-                        return null;
-                    }
-                });
-            }
-        }
+        setAccessible(constructor);
     }

     @Override

Modified: bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/model/MetaBean.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/model/MetaBean.java?rev=1628598&r1=1628597&r2=1628598&view=diff
==============================================================================
--- bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/model/MetaBean.java
(original)
+++ bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/model/MetaBean.java
Wed Oct  1 04:37:36 2014
@@ -17,6 +17,8 @@
 package org.apache.bval.model;

 import org.apache.bval.util.reflection.Reflection;
+import org.apache.commons.weaver.privilizer.Privilizing;
+import org.apache.commons.weaver.privilizer.Privilizing.CallTo;

 import java.beans.Introspector;
 import java.lang.reflect.Constructor;
@@ -34,6 +36,7 @@ import java.util.TreeMap;
  *
  * @see MetaProperty
  */
+@Privilizing(@CallTo(Reflection.class))
 public class MetaBean extends FeaturesCapable implements Cloneable,
Features.Bean {
     private static final long serialVersionUID = 2L;

@@ -280,7 +283,7 @@ public class MetaBean extends FeaturesCa
             int i = 0;
             Class<?> clazz = beanClass;
             while (clazz != null && clazz != Object.class) {
-                for (final Field f :
Reflection.INSTANCE.getDeclaredFields(clazz)) {
+                for (final Field f : Reflection.getDeclaredFields(clazz)) {
                     i++;
                     final String name = f.getName();
                     if (!fields.containsKey(name)) {
@@ -321,7 +324,7 @@ public class MetaBean extends FeaturesCa
         protected MethodComparator(final Class<?> beanClass) {
             Class<?> clazz = beanClass;
             while (clazz != null && clazz != Object.class) {
-                for (final Method m :
Reflection.INSTANCE.getDeclaredMethods(clazz)) {
+                for (final Method m : Reflection.getDeclaredMethods(clazz)) {
                     methods.put(m, Arrays.hashCode(m.getParameterTypes()));
                 }
                 clazz = clazz.getSuperclass();
@@ -345,7 +348,7 @@ public class MetaBean extends FeaturesCa
         private final Map<Constructor<?>, Integer> constructors = new
HashMap<Constructor<?>, Integer>();

         protected ConstructorComparator(final Class<?> beanClass) {
-            for (final Constructor<?> c :
Reflection.INSTANCE.getDeclaredConstructors(beanClass)) {
+            for (final Constructor<?> c :
Reflection.getDeclaredConstructors(beanClass)) {
                 constructors.put(c, Arrays.hashCode(c.getParameterTypes()));
             }
         }

Modified: bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/AccessStrategy.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/AccessStrategy.java?rev=1628598&r1=1628597&r2=1628598&view=diff
==============================================================================
--- bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/AccessStrategy.java
(original)
+++ bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/AccessStrategy.java
Wed Oct  1 04:37:36 2014
@@ -17,8 +17,11 @@
 package org.apache.bval.util;

 import java.lang.annotation.ElementType;
+import java.lang.reflect.AccessibleObject;
 import java.lang.reflect.Type;

+import org.apache.commons.weaver.privilizer.Privileged;
+
 /**
  * Description: abstract class to encapsulate different strategies
  * to get the value of a Property.  This class is designed such that
@@ -55,4 +58,21 @@ public abstract class AccessStrategy {
      * @return String
      */
     public abstract String getPropertyName();
+
+    /**
+     * Set {@code accessibleObject} as being accessible
+     * @param accessibleObject
+     */
+    protected boolean setAccessible(AccessibleObject accessibleObject) {
+        if (accessibleObject.isAccessible()) {
+            return false;
+        }
+        doSetAccessible(accessibleObject);
+        return true;
+    }
+
+    @Privileged
+    private void doSetAccessible(AccessibleObject accessibleObject) {
+        accessibleObject.setAccessible(true);
+    }
 }

Modified: bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/BValVersion.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/BValVersion.java?rev=1628598&r1=1628597&r2=1628598&view=diff
==============================================================================
--- bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/BValVersion.java
(original)
+++ bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/BValVersion.java
Wed Oct  1 04:37:36 2014
@@ -18,18 +18,21 @@
  */
 package org.apache.bval.util;

-import org.apache.bval.util.reflection.Reflection;
-
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.Properties;
 import java.util.StringTokenizer;

+import org.apache.bval.util.reflection.Reflection;
+import org.apache.commons.weaver.privilizer.Privilizing;
+import org.apache.commons.weaver.privilizer.Privilizing.CallTo;
+
 /**
  * This class contains version information for BVal.
  * It uses Ant's filter tokens to convert the template into a java
  * file with current information.
  */
+@Privilizing(@CallTo(Reflection.class))
 public class BValVersion {

     /** Project name */
@@ -157,7 +160,7 @@ public class BValVersion {
      * {@inheritDoc}
      */
     public String toString() {
-        StringBuilder buf = new StringBuilder(80 * 40);
+        final StringBuilder buf = new StringBuilder(80 * 40);
         appendBanner(buf);
         buf.append("\n");

@@ -169,8 +172,7 @@ public class BValVersion {
         appendProperty("java.vendor", buf).append("\n\n");

         buf.append("java.class.path:\n");
-        StringTokenizer tok = new StringTokenizer(
-            Reflection.INSTANCE.getProperty("java.class.path"));
+        final StringTokenizer tok = new
StringTokenizer(Reflection.getProperty("java.class.path"));
         while (tok.hasMoreTokens()) {
             buf.append("\t").append(tok.nextToken());
             buf.append("\n");
@@ -191,7 +193,6 @@ public class BValVersion {
     }

     private StringBuilder appendProperty(String prop, StringBuilder buf) {
-        return buf.append(prop).append(": ").append(
-            Reflection.INSTANCE.getProperty(prop));
+        return buf.append(prop).append(":
").append(Reflection.getProperty(prop));
     }
 }

Modified: bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/FieldAccess.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/FieldAccess.java?rev=1628598&r1=1628597&r2=1628598&view=diff
==============================================================================
--- bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/FieldAccess.java
(original)
+++ bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/FieldAccess.java
Wed Oct  1 04:37:36 2014
@@ -19,8 +19,6 @@ package org.apache.bval.util;
 import java.lang.annotation.ElementType;
 import java.lang.reflect.Field;
 import java.lang.reflect.Type;
-import java.security.AccessController;
-import java.security.PrivilegedAction;

 /**
  * Description: direct field access strategy.<br/>
@@ -35,18 +33,7 @@ public class FieldAccess extends AccessS
      */
     public FieldAccess(final Field field) {
         this.field = field;
-        if (!field.isAccessible()) {
-            if (System.getSecurityManager() == null) {
-                field.setAccessible(true);
-            } else {
-                AccessController.doPrivileged(new PrivilegedAction<Void>() {
-                    public Void run() {
-                        field.setAccessible(true);
-                        return null;
-                    }
-                });
-            }
-        }
+        setAccessible(field);
     }

     /**

Modified: bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/IndexedAccess.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/IndexedAccess.java?rev=1628598&r1=1628597&r2=1628598&view=diff
==============================================================================
--- bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/IndexedAccess.java
(original)
+++ bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/IndexedAccess.java
Wed Oct  1 04:37:36 2014
@@ -16,6 +16,7 @@
  */
 package org.apache.bval.util;

+import org.apache.commons.lang3.ObjectUtils;
 import org.apache.commons.lang3.reflect.TypeUtils;

 import java.lang.annotation.ElementType;
@@ -28,7 +29,7 @@ import java.util.Map;
 /**
  * {@link AccessStrategy} to get an indexed member of an {@link Iterable} or
  * array object.
- */
+ */
 public class IndexedAccess extends AccessStrategy {
     private static final TypeVariable<?> ITERABLE_TYPE =
Iterable.class.getTypeParameters()[0];

@@ -45,13 +46,13 @@ public class IndexedAccess extends Acces
         }
         if (TypeUtils.isAssignable(containerType, Iterable.class)) {
             Map<TypeVariable<?>, Type> typeArguments =
TypeUtils.getTypeArguments(containerType, Iterable.class);
-            return typeArguments.containsKey(ITERABLE_TYPE) ?
typeArguments.get(ITERABLE_TYPE) : Object.class;
+            return
ObjectUtils.defaultIfNull(TypeUtils.unrollVariables(typeArguments,
ITERABLE_TYPE), Object.class);
         }
         return null;
     }

-    private Type containerType;
-    private Integer index;
+    private final Type containerType;
+    private final Integer index;

     /**
      * Create a new IndexedAccessStrategy instance.

Modified: bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/KeyedAccess.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/KeyedAccess.java?rev=1628598&r1=1628597&r2=1628598&view=diff
==============================================================================
--- bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/KeyedAccess.java
(original)
+++ bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/KeyedAccess.java
Wed Oct  1 04:37:36 2014
@@ -16,6 +16,7 @@
  */
 package org.apache.bval.util;

+import org.apache.commons.lang3.ObjectUtils;
 import org.apache.commons.lang3.reflect.TypeUtils;

 import java.lang.annotation.ElementType;
@@ -43,13 +44,13 @@ public class KeyedAccess extends AccessS
     public static Type getJavaElementType(Type containerType) {
         if (TypeUtils.isAssignable(containerType, Map.class)) {
             Map<TypeVariable<?>, Type> typeArguments =
TypeUtils.getTypeArguments(containerType, Map.class);
-            return typeArguments.containsKey(MAP_TYPEVARS[1]) ?
typeArguments.get(MAP_TYPEVARS[1]) : Object.class;
+            return
ObjectUtils.defaultIfNull(TypeUtils.unrollVariables(typeArguments,
MAP_TYPEVARS[1]), Object.class);
         }
         return null;
     }

-    private Type containerType;
-    private Object key;
+    private final Type containerType;
+    private final Object key;

     /**
      * Create a new KeyedAccess instance.
@@ -71,7 +72,7 @@ public class KeyedAccess extends AccessS
         if (instance instanceof Map<?, ?>) {
             Map<?, ?> map = (Map<?, ?>) instance;
             Map<TypeVariable<?>, Type> typeArguments =
TypeUtils.getTypeArguments(containerType, Map.class);
-            Type keyType = typeArguments.get(MAP_TYPEVARS[0]);
+            Type keyType = TypeUtils.unrollVariables(typeArguments,
MAP_TYPEVARS[0]);
             if (key == null || keyType == null ||
TypeUtils.isInstance(key, keyType)) {
                 return map.get(key);
             }
@@ -106,7 +107,7 @@ public class KeyedAccess extends AccessS
      */
     @Override
     public Type getJavaType() {
-        Type result = getJavaElementType(containerType);
+        final Type result = getJavaElementType(containerType);
         return result == null ? Object.class : result;
     }


Modified: bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/MethodAccess.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/MethodAccess.java?rev=1628598&r1=1628597&r2=1628598&view=diff
==============================================================================
--- bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/MethodAccess.java
(original)
+++ bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/MethodAccess.java
Wed Oct  1 04:37:36 2014
@@ -21,8 +21,6 @@ import java.lang.annotation.ElementType;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.lang.reflect.Type;
-import java.security.AccessController;
-import java.security.PrivilegedAction;

 /**
  * Description: invoke a zero-argument method (getter)<br/>
@@ -47,18 +45,7 @@ public class MethodAccess extends Access
     public MethodAccess(String propertyName, final Method method) {
         this.method = method;
         this.propertyName = propertyName;
-        if (!method.isAccessible()) {
-            if (System.getSecurityManager() == null) {
-                method.setAccessible(true);
-            } else {
-                AccessController.doPrivileged(new PrivilegedAction<Void>() {
-                    public Void run() {
-                        method.setAccessible(true);
-                        return null;
-                    }
-                });
-            }
-        }
+        setAccessible(method);
     }

     /**
@@ -69,21 +56,14 @@ public class MethodAccess extends Access
      *         the method name id not according to the JavaBeans standard.
      */
     public static String getPropertyName(Method member) {
-        String name = null;
-        String methodName = member.getName();
+        final String methodName = member.getName();
         if (methodName.startsWith("is")) {
-            name = Introspector.decapitalize(methodName.substring(2));
-        } /* else if ( methodName.startsWith("has")) {
-                               name = Introspector.decapitalize(
methodName.substring( 3 ) );
-                       } */
-        // setter annotation is NOT supported in the spec
-        /*  else if (method.getName().startsWith("set") &&
method.getParameterTypes().length == 1) {
-           propName = Introspector.decapitalize(method.getName().substring(3));
-       } */
-        else if (methodName.startsWith("get")) {
-            name = Introspector.decapitalize(methodName.substring(3));
+            return Introspector.decapitalize(methodName.substring(2));
+        }
+        if (methodName.startsWith("get")) {
+            return Introspector.decapitalize(methodName.substring(3));
         }
-        return name;
+        return null;
     }

     /**

Modified: bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/reflection/Reflection.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/reflection/Reflection.java?rev=1628598&r1=1628597&r2=1628598&view=diff
==============================================================================
--- bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/reflection/Reflection.java
(original)
+++ bval/branches/bval-11/bval-core/src/main/java/org/apache/bval/util/reflection/Reflection.java
Wed Oct  1 04:37:36 2014
@@ -21,44 +21,122 @@ import java.lang.reflect.Constructor;
 import java.lang.reflect.Field;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;

-public interface Reflection {
-    static final Reflection INSTANCE = ReflectionFactory.newInstance();
+import org.apache.commons.lang3.ClassUtils;

-    Class<?> getClass(final ClassLoader classLoader, final String
className) throws Exception;
-
-    Object getAnnotationValue(final Annotation annotation, final
String name) throws IllegalAccessException, InvocationTargetException;
+/**
+ * Security-agnostic "blueprint" class for reflection-related operations.
+ *
+ * @version $Rev$ $Date$
+ */
+public class Reflection {
+
+    private static void setAccessibility(final Field field) {
+        // FIXME 2011-03-27 jw:
+        // - Why not simply call field.setAccessible(true)?
+        // - Fields can not be abstract.
+        if (!Modifier.isPublic(field.getModifiers())
+            || (Modifier.isPublic(field.getModifiers()) &&
Modifier.isAbstract(field.getModifiers()))) {
+            field.setAccessible(true);
+        }
+    }

-    ClassLoader getClassLoader(final Class<?> clazz);
+    public static Class<?> getClass(final ClassLoader classLoader,
final String className) throws Exception {
+        return ClassUtils.getClass(classLoader, className, true);
+    }

-    String getProperty(final String name);
+    public static Object getAnnotationValue(final Annotation
annotation, final String name)
+        throws IllegalAccessException, InvocationTargetException {
+        Method valueMethod;
+        try {
+            valueMethod = annotation.annotationType().getDeclaredMethod(name);
+        } catch (final NoSuchMethodException ex) {
+            // do nothing
+            valueMethod = null;
+        }
+        if (null != valueMethod) {
+            if (!valueMethod.isAccessible()) {
+                valueMethod.setAccessible(true);
+            }
+            return valueMethod.invoke(annotation);
+        }
+        return null;
+    }

-    Field getDeclaredField(final Class<?> clazz, final String fieldName);
+    public static ClassLoader getClassLoader(final Class<?> clazz) {
+        final ClassLoader cl = Thread.currentThread().getContextClassLoader();
+        if (cl != null) {
+            return cl;
+        }
+        return clazz.getClassLoader();
+    }

-    Field[] getDeclaredFields(final Class<?> clazz);
+    public static String getProperty(final String name) {
+        return System.getProperty(name);
+    }

-    Constructor<?> getDeclaredConstructor(final Class<?> clazz, final
Class<?>... parameters);
+    public static Field getDeclaredField(final Class<?> clazz, final
String fieldName) {
+        final Field f;
+        try {
+            f = clazz.getDeclaredField(fieldName);
+        } catch (final NoSuchFieldException e) {
+            return null;
+        }
+        setAccessibility(f);
+        return f;
+    }

-    Method getDeclaredMethod(final Class<?> clazz, final String name,
final Class<?>... parameters);
+    public static Field[] getDeclaredFields(final Class<?> clazz) {
+        final Field[] fields = clazz.getDeclaredFields();
+        if (fields.length > 0) {
+            for (final Field f : fields) {
+                if (!f.isAccessible()) {
+                    f.setAccessible(true);
+                }
+            }
+        }
+        return fields;
+    }

-    Method[] getDeclaredMethods(final Class<?> clazz);
+    public static Constructor<?> getDeclaredConstructor(final
Class<?> clazz, final Class<?>... parameters) {
+        try {
+            return clazz.getDeclaredConstructor(parameters);
+        } catch (final NoSuchMethodException e) {
+            return null;
+        }
+    }

-    Constructor<?>[] getDeclaredConstructors(final Class<?> clazz);
+    public static Method getDeclaredMethod(final Class<?> clazz,
final String name, final Class<?>... parameters) {
+        try {
+            return clazz.getDeclaredMethod(name, parameters);
+        } catch (final NoSuchMethodException e) {
+            return null;
+        }
+    }

-    Method getPublicMethod(final Class<?> clazz, final String methodName);
+    public static Method[] getDeclaredMethods(final Class<?> clazz) {
+        return clazz.getDeclaredMethods();
+    }

-    <T> T newInstance(final Class<T> cls);
+    public static Constructor<?>[] getDeclaredConstructors(final
Class<?> clazz) {
+        return clazz.getDeclaredConstructors();
+    }

-    public static class ReflectionFactory {
-        public static Reflection newInstance() {
-            if (System.getSecurityManager() != null) {
-                return new SecurityManagerReflection();
-            }
-            return new DefaultReflection();
+    public static Method getPublicMethod(final Class<?> clazz, final
String methodName) {
+        try {
+            return clazz.getMethod(methodName);
+        } catch (final NoSuchMethodException e) {
+            return null;
         }
+    }

-        private ReflectionFactory() {
-            // no-op
+    public static <T> T newInstance(final Class<T> cls) {
+        try {
+            return cls.newInstance();
+        } catch (final Exception ex) {
+            throw new RuntimeException("Cannot instantiate : " + cls, ex);
         }
     }
+
 }

Propchange: bval/branches/bval-11/bval-jsr/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Wed Oct  1 04:37:36 2014
@@ -0,0 +1,4 @@
+.classpath
+.project
+.settings
+target

Propchange: bval/branches/bval-11/bval-jsr/
------------------------------------------------------------------------------
--- svn:mergeinfo (added)
+++ svn:mergeinfo Wed Oct  1 04:37:36 2014
@@ -0,0 +1,2 @@
+/bval/trunk/bval-jsr303:1598345
+/incubator/bval/sandbox/lang3-work/bval-jsr:992137-1166425

Modified: bval/branches/bval-11/bval-jsr/pom.xml
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/pom.xml?rev=1628598&r1=1628597&r2=1628598&view=diff
==============================================================================
--- bval/branches/bval-11/bval-jsr/pom.xml (original)
+++ bval/branches/bval-11/bval-jsr/pom.xml Wed Oct  1 04:37:36 2014
@@ -79,13 +79,73 @@
                 <plugins>
                     <plugin>
                         <groupId>org.apache.maven.plugins</groupId>
+                        <artifactId>maven-resources-plugin</artifactId>
+                        <executions>
+                            <execution>
+                                <id>default-testResources</id>
+                                <phase />
+                                <goals>
+                                    <goal>testResources</goal>
+                                </goals>
+                            </execution>
+                        </executions>
+                    </plugin>
+                    <plugin>
+                        <groupId>org.apache.maven.plugins</groupId>
+                        <artifactId>maven-antrun-plugin</artifactId>
+                        <executions>
+                            <execution>
+                                <id>filter-testResources</id>
+                                <phase>process-test-resources</phase>
+                                <goals>
+                                    <goal>run</goal>
+                                </goals>
+                                <configuration>
+                                    <target>
+                                        <mkdir
dir="${project.build.testOutputDirectory}" />
+                                        <condition property="slash"
value="/" else="">
+                                            <os family="windows" />
+                                        </condition>
+                                        <copy
todir="${project.build.testOutputDirectory}" overwrite="true">
+                                            <fileset
dir="${project.basedir}/src/test/resources" excludes="java.policy" />
+                                        </copy>
+                                        <copy
todir="${project.build.testOutputDirectory}" overwrite="true">
+                                            <fileset
file="${project.basedir}/src/test/resources/java.policy" />
+                                            <filterchain>
+                                                <expandproperties />
+                                                <!-- append extra
slash on windows only -->
+                                                <replacestring
from="file://" to="file://${slash}" />
+                                                <replacestring
from="${file.separator}" to="/" />
+                                                <!-- preserve
system-specific file separator -->
+                                                <expandproperties>
+                                                    <propertyset>
+                                                        <propertyref
prefix="project." />
+                                                        <globmapper
from="*" to="preserve.*" />
+                                                    </propertyset>
+                                                </expandproperties>
+                                            </filterchain>
+                                        </copy>
+                                    </target>
+                                </configuration>
+                            </execution>
+                        </executions>
+                        <dependencies>
+                            <dependency>
+                                <groupId>org.apache.ant</groupId>
+                                <artifactId>ant</artifactId>
+                                <version>1.9.3</version>
+                            </dependency>
+                        </dependencies>
+                    </plugin>
+                    <plugin>
+                        <groupId>org.apache.maven.plugins</groupId>
                         <artifactId>maven-surefire-plugin</artifactId>
                         <configuration>
                             <includes>
                                 <include>**/*Test.java</include>
                                 <include>**/*TestCase.java</include>
                             </includes>
-                            <argLine>-Djava.security.manager
-Djava.security.policy=${project.basedir}/src/test/resources/java.policy</argLine>
+                            <argLine>-Djava.security.manager
-Djava.security.policy=${project.build.testOutputDirectory}/java.policy</argLine>
                         </configuration>
                     </plugin>
                 </plugins>
@@ -103,6 +163,10 @@
             <groupId>org.apache.commons</groupId>
             <artifactId>commons-lang3</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-weaver-privilizer-api</artifactId>
+        </dependency>
         <!-- optional dependencies -->
         <dependency>
             <groupId>org.apache.bval</groupId>
@@ -235,6 +299,10 @@
                     </includes>
                 </configuration>
             </plugin>
+            <plugin>
+                <groupId>org.apache.commons</groupId>
+                <artifactId>commons-weaver-maven-plugin</artifactId>
+            </plugin>
         </plugins>
     </build>
 </project>

Modified: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/AnnotationConstraintBuilder.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/AnnotationConstraintBuilder.java?rev=1628598&r1=1628597&r2=1628598&view=diff
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/AnnotationConstraintBuilder.java
(original)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/AnnotationConstraintBuilder.java
Wed Oct  1 04:37:36 2014
@@ -18,27 +18,9 @@
  */
 package org.apache.bval.jsr;

-import org.apache.bval.jsr.groups.GroupsComputer;
-import org.apache.bval.jsr.xml.AnnotationProxyBuilder;
-import org.apache.bval.util.AccessStrategy;
-import org.apache.commons.lang3.reflect.TypeUtils;
-
-import javax.validation.Constraint;
-import javax.validation.ConstraintDeclarationException;
-import javax.validation.ConstraintDefinitionException;
-import javax.validation.ConstraintTarget;
-import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorFactory;
-import javax.validation.OverridesAttribute;
-import javax.validation.Payload;
-import javax.validation.ReportAsSingleViolation;
-import javax.validation.constraintvalidation.SupportedValidationTarget;
-import javax.validation.constraintvalidation.ValidationTarget;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
@@ -50,6 +32,24 @@ import java.util.Set;
 import java.util.logging.Level;
 import java.util.logging.Logger;

+import javax.validation.Constraint;
+import javax.validation.ConstraintDeclarationException;
+import javax.validation.ConstraintDefinitionException;
+import javax.validation.ConstraintTarget;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorFactory;
+import javax.validation.OverridesAttribute;
+import javax.validation.Payload;
+import javax.validation.ReportAsSingleViolation;
+import javax.validation.constraintvalidation.SupportedValidationTarget;
+import javax.validation.constraintvalidation.ValidationTarget;
+
+import org.apache.bval.jsr.groups.GroupsComputer;
+import org.apache.bval.jsr.xml.AnnotationProxyBuilder;
+import org.apache.bval.util.AccessStrategy;
+import org.apache.commons.lang3.reflect.TypeUtils;
+import org.apache.commons.weaver.privilizer.Privileged;
+
 /**
  * Description: helper class that builds a {@link ConstraintValidation} or its
  * composite constraint validations by parsing the jsr-annotations and
@@ -78,22 +78,11 @@ final class AnnotationConstraintBuilder<
     }

     /** build attributes, payload, groups from 'annotation' */
+    @Privileged
     private void buildFromAnnotation() {
-        if (constraintValidation.getAnnotation() != null) {
-            if (System.getSecurityManager() == null) {
-                doBuildFromAnnotations();
-            } else {
-                AccessController.doPrivileged(new PrivilegedAction<Object>() {
-                    public Object run() {
-                        doBuildFromAnnotations();
-                        return null;
-                    }
-                });
-            }
+        if (constraintValidation.getAnnotation() == null) {
+            return;
         }
-    }
-
-    private void doBuildFromAnnotations() {
         final Class<? extends Annotation> annotationType =
constraintValidation.getAnnotation().annotationType();

         boolean foundPayload = false;

Modified: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/AnnotationProcessor.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/AnnotationProcessor.java?rev=1628598&r1=1628597&r2=1628598&view=diff
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/AnnotationProcessor.java
(original)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/AnnotationProcessor.java
Wed Oct  1 04:37:36 2014
@@ -24,6 +24,8 @@ import org.apache.bval.model.MetaBean;
 import org.apache.bval.util.AccessStrategy;
 import org.apache.bval.util.reflection.Reflection;
 import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.weaver.privilizer.Privilizing;
+import org.apache.commons.weaver.privilizer.Privilizing.CallTo;

 import javax.validation.Constraint;
 import javax.validation.ConstraintValidator;
@@ -32,6 +34,7 @@ import javax.validation.constraintvalida
 import javax.validation.constraintvalidation.ValidationTarget;
 import javax.validation.groups.ConvertGroup;
 import javax.validation.groups.Default;
+
 import java.lang.annotation.Annotation;
 import java.lang.reflect.AnnotatedElement;
 import java.lang.reflect.InvocationTargetException;
@@ -44,6 +47,7 @@ import java.util.Set;
  * annotations, including composed constraints and the resolution of
  * {@link ConstraintValidator} implementations.
  */
+@Privilizing(@CallTo(Reflection.class))
 public final class AnnotationProcessor {
     /** {@link ApacheFactoryContext} used */
     private final ApacheFactoryContext factoryContext;
@@ -142,7 +146,8 @@ public final class AnnotationProcessor {
          * annotated by @Constraint) whose value element has a return
type of an
          * array of constraint annotations in a special way.
          */
-        final Object result =
Reflection.INSTANCE.getAnnotationValue(annotation,
ConstraintAnnotationAttributes.VALUE.getAttributeName());
+        final Object result =
+            Reflection.getAnnotationValue(annotation,
ConstraintAnnotationAttributes.VALUE.getAttributeName());
         if (result instanceof Annotation[]) {
             boolean changed = false;
             for (final Annotation each : (Annotation[]) result) {

Modified: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ApacheFactoryContext.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ApacheFactoryContext.java?rev=1628598&r1=1628597&r2=1628598&view=diff
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ApacheFactoryContext.java
(original)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ApacheFactoryContext.java
Wed Oct  1 04:37:36 2014
@@ -18,6 +18,18 @@
  */
 package org.apache.bval.jsr;

+import java.lang.reflect.Constructor;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.validation.ConstraintValidatorFactory;
+import javax.validation.MessageInterpolator;
+import javax.validation.ParameterNameProvider;
+import javax.validation.TraversableResolver;
+import javax.validation.ValidationException;
+import javax.validation.Validator;
+import javax.validation.ValidatorContext;
+
 import org.apache.bval.IntrospectorMetaBeanFactory;
 import org.apache.bval.MetaBeanBuilder;
 import org.apache.bval.MetaBeanFactory;
@@ -29,24 +41,15 @@ import org.apache.bval.xml.XMLMetaBeanFa
 import org.apache.bval.xml.XMLMetaBeanManager;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.reflect.ConstructorUtils;
-
-import javax.validation.ConstraintValidatorFactory;
-import javax.validation.MessageInterpolator;
-import javax.validation.ParameterNameProvider;
-import javax.validation.TraversableResolver;
-import javax.validation.ValidationException;
-import javax.validation.Validator;
-import javax.validation.ValidatorContext;
-import java.lang.reflect.Constructor;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.util.ArrayList;
-import java.util.List;
+import org.apache.commons.weaver.privilizer.Privileged;
+import org.apache.commons.weaver.privilizer.Privilizing;
+import org.apache.commons.weaver.privilizer.Privilizing.CallTo;

 /**
  * Description: Represents the context that is used to create
  * <code>ClassValidator</code> instances.<br/>
  */
+@Privilizing(@CallTo(Reflection.class))
 public class ApacheFactoryContext implements ValidatorContext {
     private final ApacheValidatorFactory factory;
     private final MetaBeanFinder metaBeanFinder;
@@ -238,18 +241,8 @@ public class ApacheFactoryContext implem
         return new MetaBeanManager(new
MetaBeanBuilder(builders.toArray(new
MetaBeanFactory[builders.size()])));
     }

+    @Privileged
     private <F extends MetaBeanFactory> F createMetaBeanFactory(final
Class<F> cls) {
-        if (System.getSecurityManager() == null) {
-            return doCreateMetaBeanFactory(cls);
-        }
-        return AccessController.doPrivileged(new PrivilegedAction<F>() {
-            public F run() {
-                return doCreateMetaBeanFactory(cls);
-            }
-        });
-    }
-
-    private <F extends MetaBeanFactory> F
doCreateMetaBeanFactory(final Class<F> cls) {
         try {
             Constructor<F> c =
ConstructorUtils.getMatchingAccessibleConstructor(cls,
ApacheFactoryContext.this.getClass());
             if (c != null) {
@@ -294,7 +287,7 @@ public class ApacheFactoryContext implem

     private Class<?> loadClass(final String className) {
         try {
-            return Class.forName(className, true,
Reflection.INSTANCE.getClassLoader(ApacheFactoryContext.class));
+            return Class.forName(className, true,
Reflection.getClassLoader(ApacheFactoryContext.class));
         } catch (ClassNotFoundException ex) {
             throw new ValidationException("Unable to load class: " +
className, ex);
         }

Modified: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ApacheValidationProvider.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ApacheValidationProvider.java?rev=1628598&r1=1628597&r2=1628598&view=diff
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ApacheValidationProvider.java
(original)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ApacheValidationProvider.java
Wed Oct  1 04:37:36 2014
@@ -18,16 +18,15 @@
  */
 package org.apache.bval.jsr;

-import org.apache.commons.lang3.ClassUtils;
-
 import javax.validation.Configuration;
 import javax.validation.ValidationException;
 import javax.validation.ValidatorFactory;
 import javax.validation.spi.BootstrapState;
 import javax.validation.spi.ConfigurationState;
 import javax.validation.spi.ValidationProvider;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
+
+import org.apache.commons.lang3.ClassUtils;
+import org.apache.commons.weaver.privilizer.Privileged;

 /**
  * Description: Implementation of {@link ValidationProvider} for jsr
@@ -98,15 +97,10 @@ public class ApacheValidationProvider im
         // No privileges should be required to access the constructor,
         // because the classloader of ApacheValidationProvider will always
         // be an ancestor of the loader of validatorFactoryClass.
-        return (System.getSecurityManager() == null)
-            ? instantiateValidatorFactory(validatorFactoryClass,
configuration) : AccessController
-                .doPrivileged(new PrivilegedAction<ValidatorFactory>() {
-                    public ValidatorFactory run() {
-                        return
instantiateValidatorFactory(validatorFactoryClass, configuration);
-                    }
-                });
+        return instantiateValidatorFactory(validatorFactoryClass,
configuration);
     }

+    @Privileged
     private static ValidatorFactory instantiateValidatorFactory(
         final Class<? extends ValidatorFactory>
validatorFactoryClass, final ConfigurationState configuration) {
         try {

Modified: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ApacheValidatorConfiguration.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ApacheValidatorConfiguration.java?rev=1628598&r1=1628597&r2=1628598&view=diff
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ApacheValidatorConfiguration.java
(original)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ApacheValidatorConfiguration.java
Wed Oct  1 04:37:36 2014
@@ -72,7 +72,7 @@ public interface ApacheValidatorConfigur
          * class is presumed have a constructor that accepts a single
          * {@link ConfigurationState} argument.
          */
-         String VALIDATOR_FACTORY_CLASSNAME =
"apache.bval.validator-factory-classname";
+        String VALIDATOR_FACTORY_CLASSNAME =
"apache.bval.validator-factory-classname";

         /**
          * Specifies the names, delimited by whitespace, of
@@ -86,6 +86,6 @@ public interface ApacheValidatorConfigur
          * <li>default (no-args) constructor</li>
          * </ol>
          */
-         String METABEAN_FACTORY_CLASSNAMES =
"apache.bval.metabean-factory-classnames";
+        String METABEAN_FACTORY_CLASSNAMES =
"apache.bval.metabean-factory-classnames";
     }
 }

Modified: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ApacheValidatorFactory.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ApacheValidatorFactory.java?rev=1628598&r1=1628597&r2=1628598&view=diff
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ApacheValidatorFactory.java
(original)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ApacheValidatorFactory.java
Wed Oct  1 04:37:36 2014
@@ -25,6 +25,8 @@ import org.apache.bval.util.AccessStrate
 import org.apache.bval.util.reflection.Reflection;
 import org.apache.commons.lang3.ArrayUtils;
 import org.apache.commons.lang3.ClassUtils;
+import org.apache.commons.weaver.privilizer.Privilizing;
+import org.apache.commons.weaver.privilizer.Privilizing.CallTo;

 import javax.validation.ConstraintValidatorFactory;
 import javax.validation.MessageInterpolator;
@@ -35,6 +37,7 @@ import javax.validation.ValidationExcept
 import javax.validation.Validator;
 import javax.validation.ValidatorFactory;
 import javax.validation.spi.ConfigurationState;
+
 import java.io.Closeable;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Modifier;
@@ -52,6 +55,7 @@ import java.util.concurrent.ConcurrentMa
  * validators.<br/>
  * This instance is not thread-safe.<br/>
  */
+@Privilizing(@CallTo(Reflection.class))
 public class ApacheValidatorFactory implements ValidatorFactory, Cloneable {
     private static volatile ApacheValidatorFactory DEFAULT_FACTORY;
     private static final ConstraintDefaults DEFAULT_CONSTRAINTS = new
ConstraintDefaults();
@@ -295,7 +299,7 @@ public class ApacheValidatorFactory impl

     private <T> T newInstance(final Class<T> cls) {
         try {
-            return Reflection.INSTANCE.newInstance(cls);
+            return Reflection.newInstance(cls);
         } catch (final RuntimeException e) {
             throw new ValidationException(e.getCause());
         }

Modified: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/BeanDescriptorImpl.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/BeanDescriptorImpl.java?rev=1628598&r1=1628597&r2=1628598&view=diff
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/BeanDescriptorImpl.java
(original)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/BeanDescriptorImpl.java
Wed Oct  1 04:37:36 2014
@@ -33,6 +33,8 @@ import org.apache.bval.model.Validation;
 import org.apache.bval.util.AccessStrategy;
 import org.apache.bval.util.reflection.Reflection;
 import org.apache.commons.lang3.ClassUtils;
+import org.apache.commons.weaver.privilizer.Privilizing;
+import org.apache.commons.weaver.privilizer.Privilizing.CallTo;

 import javax.validation.Constraint;
 import javax.validation.ConstraintDeclarationException;
@@ -49,6 +51,7 @@ import javax.validation.metadata.MethodT
 import javax.validation.metadata.ParameterDescriptor;
 import javax.validation.metadata.PropertyDescriptor;
 import javax.validation.metadata.ReturnValueDescriptor;
+
 import java.beans.Introspector;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.AccessibleObject;
@@ -72,6 +75,7 @@ import java.util.concurrent.CopyOnWriteA
 /**
  * Description: Implements {@link BeanDescriptor}.<br/>
  */
+@Privilizing(@CallTo(Reflection.class))
 public class BeanDescriptorImpl extends ElementDescriptorImpl
implements BeanDescriptor {
     private static final CopyOnWriteArraySet<ConstraintValidation<?>>
NO_CONSTRAINTS = new CopyOnWriteArraySet<ConstraintValidation<?>>();
     private static final Validation[] EMPTY_VALIDATION = new Validation[0];
@@ -120,7 +124,7 @@ public class BeanDescriptorImpl extends
         Class<?> current = prop.getParentMetaBean().getBeanClass();
         while (current != null && current != Object.class &&
(!methodFound || !fieldFound)) {
             if (!fieldFound) {
-                final Field field =
Reflection.INSTANCE.getDeclaredField(current, prop.getName());
+                final Field field =
Reflection.getDeclaredField(current, prop.getName());
                 if (field != null) {
                     processConvertGroup(edesc, field);
                     fieldFound = true;
@@ -129,12 +133,12 @@ public class BeanDescriptorImpl extends

             if (!methodFound) {
                 final String name =
Character.toUpperCase(prop.getName().charAt(0)) +
prop.getName().substring(1);
-                Method m =
Reflection.INSTANCE.getDeclaredMethod(current, "get" + name);
+                Method m = Reflection.getDeclaredMethod(current, "get" + name);
                 if (m != null) {
                     processConvertGroup(edesc, m);
                     methodFound = true;
                 } else {
-                    m =
Reflection.INSTANCE.getDeclaredMethod(current, "is" + name);
+                    m = Reflection.getDeclaredMethod(current, "is" + name);
                     if (m != null) {
                         processConvertGroup(edesc, m);
                         methodFound = true;
@@ -359,7 +363,7 @@ public class BeanDescriptorImpl extends
         }

         private void buildConstructorConstraints() throws
InvocationTargetException, IllegalAccessException {
-            for (final Constructor<?> cons :
Reflection.INSTANCE.getDeclaredConstructors(metaBean.getBeanClass()))
{
+            for (final Constructor<?> cons :
Reflection.getDeclaredConstructors(metaBean.getBeanClass())) {
                 final ConstructorDescriptorImpl consDesc = new
ConstructorDescriptorImpl(metaBean, EMPTY_VALIDATION);

contructorConstraints.put(Arrays.toString(cons.getParameterTypes()),
consDesc);

@@ -500,7 +504,7 @@ public class BeanDescriptorImpl extends
             final List<Class<?>> classHierarchy =
ClassHelper.fillFullClassHierarchyAsList(new ArrayList<Class<?>>(),
current);
             classHierarchy.remove(current);

-            for (final Method method :
Reflection.INSTANCE.getDeclaredMethods(current)) {
+            for (final Method method :
Reflection.getDeclaredMethods(current)) {
                 if (Modifier.isStatic(method.getModifiers()) ||
method.isSynthetic()) {
                     continue;
                 }
@@ -518,10 +522,10 @@ public class BeanDescriptorImpl extends

                 final Collection<Method> parents = new ArrayList<Method>();
                 for (final Class<?> clazz : classHierarchy) {
-                    final Method overriden =
Reflection.INSTANCE.getDeclaredMethod(clazz, method.getName(),
method.getParameterTypes());
-                    if (overriden != null) {
-                        parents.add(overriden);
-                        processMethod(overriden, methodDesc);
+                    final Method overridden =
Reflection.getDeclaredMethod(clazz, method.getName(),
method.getParameterTypes());
+                    if (overridden != null) {
+                        parents.add(overridden);
+                        processMethod(overridden, methodDesc);
                     }
                 }

@@ -564,7 +568,7 @@ public class BeanDescriptorImpl extends
                     final Class<?>[] interfaces =
method.getDeclaringClass().getInterfaces();
                     final Collection<Method> itfWithThisMethod = new
ArrayList<Method>();
                     for (final Class<?> i : interfaces) {
-                        final Method m =
Reflection.INSTANCE.getDeclaredMethod(i, method.getName(),
method.getParameterTypes());
+                        final Method m =
Reflection.getDeclaredMethod(i, method.getName(),
method.getParameterTypes());
                         if (m != null) {
                             itfWithThisMethod.add(m);
                         }
@@ -582,9 +586,9 @@ public class BeanDescriptorImpl extends
                         returnValid++;
                     }
                     for (final Class<?> clazz : classHierarchy) {
-                        final Method overriden =
Reflection.INSTANCE.getDeclaredMethod(clazz, method.getName(),
method.getParameterTypes());
-                        if (overriden != null) {
-                            if (overriden.getAnnotation(Valid.class) != null) {
+                        final Method overridden =
Reflection.getDeclaredMethod(clazz, method.getName(),
method.getParameterTypes());
+                        if (overridden != null) {
+                            if (overridden.getAnnotation(Valid.class)
!= null) {
                                 returnValid++;
                             }
                         }

Modified: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ClassValidator.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ClassValidator.java?rev=1628598&r1=1628597&r2=1628598&view=diff
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ClassValidator.java
(original)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ClassValidator.java
Wed Oct  1 04:37:36 2014
@@ -18,6 +18,33 @@
  */
 package org.apache.bval.jsr;

+import java.lang.reflect.Constructor;
+import java.lang.reflect.Member;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.validation.ConstraintDeclarationException;
+import javax.validation.ConstraintDefinitionException;
+import javax.validation.ConstraintTarget;
+import javax.validation.ConstraintViolation;
+import javax.validation.ElementKind;
+import javax.validation.ValidationException;
+import javax.validation.executable.ExecutableValidator;
+import javax.validation.groups.Default;
+import javax.validation.metadata.BeanDescriptor;
+import javax.validation.metadata.ConstraintDescriptor;
+import javax.validation.metadata.ElementDescriptor;
+import javax.validation.metadata.ParameterDescriptor;
+import javax.validation.metadata.PropertyDescriptor;
+
 import org.apache.bval.DynamicMetaBean;
 import org.apache.bval.MetaBeanFinder;
 import org.apache.bval.jsr.groups.Group;
@@ -40,34 +67,7 @@ import org.apache.commons.lang3.ArrayUti
 import org.apache.commons.lang3.ClassUtils;
 import org.apache.commons.lang3.ObjectUtils;
 import org.apache.commons.lang3.reflect.TypeUtils;
-
-import javax.validation.ConstraintDeclarationException;
-import javax.validation.ConstraintDefinitionException;
-import javax.validation.ConstraintTarget;
-import javax.validation.ConstraintViolation;
-import javax.validation.ElementKind;
-import javax.validation.ValidationException;
-import javax.validation.executable.ExecutableValidator;
-import javax.validation.groups.Default;
-import javax.validation.metadata.BeanDescriptor;
-import javax.validation.metadata.ConstraintDescriptor;
-import javax.validation.metadata.ElementDescriptor;
-import javax.validation.metadata.ParameterDescriptor;
-import javax.validation.metadata.PropertyDescriptor;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Member;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import org.apache.commons.weaver.privilizer.Privileged;

 // TODO: centralize treatMapsLikeBeans

@@ -312,18 +312,8 @@ public class ClassValidator implements C
         return this;
     }

+    @Privileged
     private <T> T newInstance(final Class<T> cls) {
-        if (System.getSecurityManager() == null) {
-            return doNewInstance(cls);
-        }
-        return AccessController.doPrivileged(new PrivilegedAction<T>() {
-            public T run() {
-                return doNewInstance(cls);
-            }
-        });
-    }
-
-    private <T> T doNewInstance(final Class<T> cls) {
         try {
             Constructor<T> cons =
cls.getConstructor(ApacheFactoryContext.class);
             if (!cons.isAccessible()) {
@@ -399,6 +389,7 @@ public class ClassValidator implements C

                 // For each owner in the hierarchy
                 for (final Class<?> owner : classHierarchy) {
+
                     context.setCurrentOwner(owner);

                     int numViolations = result.violationsSize();

Modified: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ConfigurationImpl.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ConfigurationImpl.java?rev=1628598&r1=1628597&r2=1628598&view=diff
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ConfigurationImpl.java
(original)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ConfigurationImpl.java
Wed Oct  1 04:37:36 2014
@@ -18,11 +18,16 @@
  */
 package org.apache.bval.jsr;

-import org.apache.bval.cdi.BValExtension;
-import org.apache.bval.jsr.parameter.DefaultParameterNameProvider;
-import org.apache.bval.jsr.resolver.DefaultTraversableResolver;
-import org.apache.bval.jsr.util.IOs;
-import org.apache.bval.jsr.xml.ValidationParser;
+import java.io.Closeable;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.CopyOnWriteArrayList;

 import javax.validation.BootstrapConfiguration;
 import javax.validation.ConstraintValidatorFactory;
@@ -36,18 +41,13 @@ import javax.validation.executable.Execu
 import javax.validation.spi.BootstrapState;
 import javax.validation.spi.ConfigurationState;
 import javax.validation.spi.ValidationProvider;
-import java.io.Closeable;
-import java.io.IOException;
-import java.io.InputStream;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.apache.bval.cdi.BValExtension;
+import org.apache.bval.jsr.parameter.DefaultParameterNameProvider;
+import org.apache.bval.jsr.resolver.DefaultTraversableResolver;
+import org.apache.bval.jsr.util.IOs;
+import org.apache.bval.jsr.xml.ValidationParser;
+import org.apache.commons.weaver.privilizer.Privileged;

 /**
  * Description: used to configure apache-validation for jsr.
@@ -98,7 +98,7 @@ public class ConfigurationImpl implement

     protected Collection<ExecutableType> executableValidation;

-    private Collection<BValExtension.Releasable> releasables = new
CopyOnWriteArrayList<BValExtension.Releasable>();
+    private Collection<BValExtension.Releasable<?>> releasables = new
CopyOnWriteArrayList<BValExtension.Releasable<?>>();

     private boolean beforeCdi = false;

@@ -305,27 +305,18 @@ public class ConfigurationImpl implement
      * @throws ValidationException if the ValidatorFactory cannot be built
      */
     public ValidatorFactory buildValidatorFactory() {
-        if (System.getSecurityManager() == null) {
-            return doPrivBuildValidatorFactory(this);
-        }
-        return AccessController.doPrivileged(new
PrivilegedAction<ValidatorFactory>() {
-            public ValidatorFactory run() {
-                return doPrivBuildValidatorFactory(ConfigurationImpl.this);
-            }
-        });
+            return doBuildValidatorFactory();
     }

-    public ValidatorFactory doPrivBuildValidatorFactory(final
ConfigurationImpl impl) {
+    @Privileged
+    private ValidatorFactory doBuildValidatorFactory() {
         prepare();
         parser.ensureValidatorFactoryCanBeBuilt();
-        if (provider != null) {
-            return provider.buildValidatorFactory(impl);
-        } else {
-            return findProvider().buildValidatorFactory(impl);
-        }
+        final ValidationProvider<?> useProvider = provider == null ?
findProvider() : provider;
+        return useProvider.buildValidatorFactory(this);
     }

-    public ConfigurationImpl prepare() {
+    private ConfigurationImpl prepare() {
         if (prepared) {
             return this;
         }
@@ -466,38 +457,19 @@ public class ConfigurationImpl implement
         };
     }

+    @Privileged
     private <T> T newInstance(final Class<T> cls) {
-        if (System.getSecurityManager() == null) {
-            return createInstance(cls);
-        }
-        return AccessController.doPrivileged(new PrivilegedAction<T>() {
-            public T run() {
-                return createInstance(cls);
-            }
-        });
-    }
-
-    private <T> T createInstance(final Class<T> cls) {
         try {
             final BValExtension.Releasable<T> releasable =
BValExtension.inject(cls);
             releasables.add(releasable);
             return releasable.getInstance();
         } catch (final Exception e) {
-            try {
-                return cls.newInstance();
-            } catch (final InstantiationException e1) {
-                throw new ValidationException(e1.getMessage(), e1);
-            } catch (final IllegalAccessException e1) {
-                throw new ValidationException(e1.getMessage(), e1);
-            }
         } catch (final NoClassDefFoundError error) {
-            try {
-                return cls.newInstance();
-            } catch (final InstantiationException e1) {
-                throw new ValidationException(e1.getMessage(), e1);
-            } catch (final IllegalAccessException e1) {
-                throw new ValidationException(e1.getMessage(), e1);
-            }
+        }
+        try {
+            return cls.newInstance();
+        } catch (final Exception e) {
+            throw new ValidationException(e.getMessage(), e);
         }
     }


Modified: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ConstraintAnnotationAttributes.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ConstraintAnnotationAttributes.java?rev=1628598&r1=1628597&r2=1628598&view=diff
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ConstraintAnnotationAttributes.java
(original)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ConstraintAnnotationAttributes.java
Wed Oct  1 04:37:36 2014
@@ -18,15 +18,17 @@ package org.apache.bval.jsr;

 import org.apache.bval.util.reflection.Reflection;
 import org.apache.commons.lang3.reflect.TypeUtils;
+import org.apache.commons.weaver.privilizer.Privileged;
+import org.apache.commons.weaver.privilizer.Privilizing;
+import org.apache.commons.weaver.privilizer.Privilizing.CallTo;

 import javax.validation.Constraint;
 import javax.validation.ConstraintTarget;
 import javax.validation.Payload;
+
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
 import java.lang.reflect.Type;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
@@ -40,27 +42,27 @@ public enum ConstraintAnnotationAttribut
     /**
      * "message"
      */
-    MESSAGE(false, "message"),
+    MESSAGE("message"),

     /**
      * "groups"
      */
-    GROUPS(false, "groups"),
+    GROUPS("groups"),

     /**
      * "payload"
      */
-    PAYLOAD(false, "payload"),
+    PAYLOAD("payload"),

     /**
      * "validationAppliesTo"
      */
-    VALIDATION_APPLIES_TO(true, "validationAppliesTo"),
+    VALIDATION_APPLIES_TO("validationAppliesTo"),

     /**
      * "value" for multi-valued constraints
      */
-    VALUE(true, "value");
+    VALUE("value");

     @SuppressWarnings("unused")
     private static class Types {
@@ -72,11 +74,9 @@ public enum ConstraintAnnotationAttribut
     }

     private final Type type;
-    private final boolean permitNullDefaultValue;
     private final String attributeName;

-    private ConstraintAnnotationAttributes(final boolean
permitNullDefaultValue, final String name) {
-        this.permitNullDefaultValue = permitNullDefaultValue;
+    private ConstraintAnnotationAttributes(final String name) {
         this.attributeName = name;
         try {
             this.type =
Types.class.getDeclaredField(getAttributeName()).getGenericType();
@@ -133,6 +133,7 @@ public enum ConstraintAnnotationAttribut

     public <C extends Annotation> Worker<C> analyze(final Class<C> clazz) {
         if (clazz.getName().startsWith("javax.validation.constraint."))
{ // cache only APIs classes to avoid memory leaks
+            @SuppressWarnings("unchecked")
             Worker<C> w = Worker.class.cast(WORKER_CACHE.get(clazz));
             if (w == null) {
                 w = new Worker<C>(clazz);
@@ -154,6 +155,8 @@ public enum ConstraintAnnotationAttribut
             throw new RuntimeException("Impossible normally");
         }
     }
+
+    @Privilizing(@CallTo(Reflection.class))
     public class Worker<C extends Annotation> {

         public final Method method;
@@ -180,7 +183,7 @@ public enum ConstraintAnnotationAttribut
             if (found != null) {
                 return found;
             }
-            final Method m =
Reflection.INSTANCE.getPublicMethod(constraintType, attributeName);
+            final Method m =
Reflection.getPublicMethod(constraintType, attributeName);
             if (m == null) {
                 cache.putIfAbsent(attributeName, NULL_METHOD);
                 return null;
@@ -199,17 +202,13 @@ public enum ConstraintAnnotationAttribut
             return method != null && method != NULL_METHOD;
         }

-        public Object read(final Annotation constraint) {
-            if (System.getSecurityManager() == null) {
-                return doInvoke(constraint);
-            }
-            return AccessController.doPrivileged(new
PrivilegedAction<Object>() {
-                public Object run() {
-                    return doInvoke(constraint);
-                }
-            });
+        public <T> T read(final Annotation constraint) {
+            @SuppressWarnings("unchecked")
+            final T result = (T) doInvoke(constraint);
+            return result;
         }

+        @Privileged
         private Object doInvoke(final Annotation constraint) {
             try {
                 return method.invoke(constraint);

Modified: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ConstraintDefaults.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ConstraintDefaults.java?rev=1628598&r1=1628597&r2=1628598&view=diff
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ConstraintDefaults.java
(original)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ConstraintDefaults.java
Wed Oct  1 04:37:36 2014
@@ -18,12 +18,9 @@
  */
 package org.apache.bval.jsr;

-import javax.validation.ConstraintValidator;
 import java.io.IOException;
 import java.io.InputStream;
 import java.lang.annotation.Annotation;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
 import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.Map;
@@ -32,10 +29,17 @@ import java.util.StringTokenizer;
 import java.util.logging.Level;
 import java.util.logging.Logger;

+import javax.validation.ConstraintValidator;
+
+import org.apache.bval.util.reflection.Reflection;
+import org.apache.commons.weaver.privilizer.Privilizing;
+import org.apache.commons.weaver.privilizer.Privilizing.CallTo;
+
 /**
  * Description: Provides access to the default constraints/validator
implementation classes built into the framework.
  * These are configured in DefaultConstraints.properties.<br/>
  */
+@Privilizing(@CallTo(Reflection.class))
 public class ConstraintDefaults {
     private static final Logger log =
Logger.getLogger(ConstraintDefaults.class.getName());
     private static final String DEFAULT_CONSTRAINTS =
@@ -101,31 +105,11 @@ public class ConstraintDefaults {
             while (tokens.hasMoreTokens()) {
                 final String eachClassName = tokens.nextToken();

-                Class<?> constraintValidatorClass;
-                if (System.getSecurityManager() == null) {
-                    try {
-                        constraintValidatorClass =
Class.forName(eachClassName, true, classloader);
-                    } catch (final ClassNotFoundException e) {
-                        log.log(Level.SEVERE, String.format("Cannot
find class %s", eachClassName), e);
-                        constraintValidatorClass = null;
-                    }
-                } else {
-                    constraintValidatorClass =
AccessController.doPrivileged(new PrivilegedAction<Class<?>>() {
-                          public Class<?> run() {
-                              try {
-                                  return Class.forName(eachClassName,
true, classloader);
-                              } catch (final ClassNotFoundException e) {
-                                  log.log(Level.SEVERE,
String.format("Cannot find class %s", eachClassName), e);
-                                  return null;
-                              }
-                          }
-                      });
-                }
-
-                if (constraintValidatorClass != null) {
-                    classes.add(constraintValidatorClass);
+                try {
+                    classes.add(Reflection.getClass(classloader,
eachClassName));
+                } catch (Exception e) {
+                    log.log(Level.SEVERE, String.format("Cannot find
class %s", eachClassName), e);
                 }
-
             }

             loadedConstraints.put((String) entry.getKey(),
classes.toArray(new Class[classes.size()]));

Modified: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ConstraintValidation.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ConstraintValidation.java?rev=1628598&r1=1628597&r2=1628598&view=diff
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ConstraintValidation.java
(original)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ConstraintValidation.java
Wed Oct  1 04:37:36 2014
@@ -234,7 +234,7 @@ public class ConstraintValidation<T exte
     }

     private <A extends Annotation, T> ConstraintValidator<A, ? super
T> getConstraintValidator(A annotation,
-
                         Class<? extends ConstraintValidator<A, ?>>[]
constraintClasses, Class<?> owner, AccessStrategy access) {
+        Class<? extends ConstraintValidator<A, ?>>[]
constraintClasses, Class<?> owner, AccessStrategy access) {
         if (constraintClasses != null && constraintClasses.length > 0) {
             Type type = determineTargetedType(owner, access);


Modified: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/DefaultMessageInterpolator.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/DefaultMessageInterpolator.java?rev=1628598&r1=1628597&r2=1628598&view=diff
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/DefaultMessageInterpolator.java
(original)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/DefaultMessageInterpolator.java
Wed Oct  1 04:37:36 2014
@@ -19,8 +19,11 @@ package org.apache.bval.jsr;
 import org.apache.bval.el.MessageEvaluator;
 import org.apache.bval.util.reflection.Reflection;
 import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.weaver.privilizer.Privilizing;
+import org.apache.commons.weaver.privilizer.Privilizing.CallTo;

 import javax.validation.MessageInterpolator;
+
 import java.util.Locale;
 import java.util.Map;
 import java.util.MissingResourceException;
@@ -37,6 +40,7 @@ import java.util.regex.Pattern;
  * into human-readable messages. It uses ResourceBundles to find the messages.
  * This class is threadsafe.<br/>
  */
+@Privilizing(@CallTo(Reflection.class))
 public class DefaultMessageInterpolator implements MessageInterpolator {
     private static final Logger log =
Logger.getLogger(DefaultMessageInterpolator.class.getName());
     private static final boolean LOG_FINEST = log.isLoggable(Level.FINEST);
@@ -168,7 +172,7 @@ public class DefaultMessageInterpolator
      */
     private ResourceBundle getFileBasedResourceBundle(Locale locale) {
         ResourceBundle rb = null;
-        final ClassLoader classLoader =
Reflection.INSTANCE.getClassLoader(DefaultMessageInterpolator.class);
+        final ClassLoader classLoader =
Reflection.getClassLoader(DefaultMessageInterpolator.class);
         if (classLoader != null) {
             rb = loadBundle(classLoader, locale,
                   USER_VALIDATION_MESSAGES + " not found by thread
local classloader");

Modified: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/DefaultValidationProviderResolver.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/DefaultValidationProviderResolver.java?rev=1628598&r1=1628597&r2=1628598&view=diff
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/DefaultValidationProviderResolver.java
(original)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/DefaultValidationProviderResolver.java
Wed Oct  1 04:37:36 2014
@@ -17,19 +17,23 @@
 package org.apache.bval.jsr;


-import javax.validation.ValidationException;
-import javax.validation.ValidationProviderResolver;
-import javax.validation.spi.ValidationProvider;
 import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.net.URL;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
 import java.util.ArrayList;
 import java.util.Enumeration;
 import java.util.List;

+import javax.validation.ValidationException;
+import javax.validation.ValidationProviderResolver;
+import javax.validation.spi.ValidationProvider;
+
+import org.apache.bval.util.reflection.Reflection;
+import org.apache.commons.weaver.privilizer.Privilizing;
+import org.apache.commons.weaver.privilizer.Privilizing.CallTo;
+
+@Privilizing(@CallTo(Reflection.class))
 public class DefaultValidationProviderResolver implements
ValidationProviderResolver {

     //TODO - Spec recommends caching per classloader
@@ -49,7 +53,7 @@ public class DefaultValidationProviderRe
             // find all service provider cfgs
             Enumeration<URL> cfgs = cl.getResources(SPI_CFG);
             while (cfgs.hasMoreElements()) {
-                URL url = cfgs.nextElement();
+                final URL url = cfgs.nextElement();
                 BufferedReader br = null;
                 try {
                     br = new BufferedReader(new
InputStreamReader(url.openStream()), 256);
@@ -60,27 +64,11 @@ public class DefaultValidationProviderRe
                         if (!line.startsWith("#")) {
                             try {
                                 // try loading the specified class
-                                final Class<?> provider = cl.loadClass(line);
+                                @SuppressWarnings("rawtypes")
+                                final Class<? extends
ValidationProvider> providerType =
+
cl.loadClass(line).asSubclass(ValidationProvider.class);
                                 // create an instance to return
-                                final ValidationProvider<?> vp;
-                                if (System.getSecurityManager() == null) {
-                                    try {
-                                        vp = (ValidationProvider<?>)
provider.newInstance();
-                                    } catch (final Exception ex) {
-                                        throw new
ValidationException("Cannot instantiate : " + provider, ex);
-                                    }
-                                } else {
-                                    vp =
AccessController.doPrivileged(new
PrivilegedAction<ValidationProvider<?>>() {
-                                        public ValidationProvider<?> run() {
-                                            try {
-                                                return
(ValidationProvider<?>) provider.newInstance();
-                                            } catch (final Exception ex) {
-                                                throw new
ValidationException("Cannot instantiate : " + provider, ex);
-                                            }
-                                        }
-                                    });
-                                }
-                                providers.add(vp);
+
providers.add(Reflection.newInstance(providerType.asSubclass(ValidationProvider.class)));

                             } catch (ClassNotFoundException e) {
                                 throw new ValidationException("Failed
to load provider " +
@@ -89,12 +77,12 @@ public class DefaultValidationProviderRe
                         }
                         line = br.readLine();
                     }
-                    br.close();
                 } catch (IOException e) {
                     throw new ValidationException("Error trying to
read " + url, e);
                 } finally {
-                    if (br != null)
+                    if (br != null) {
                         br.close();
+                    }
                 }
             }
         } catch (IOException e) {

Modified: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/JsrMetaBeanFactory.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/JsrMetaBeanFactory.java?rev=1628598&r1=1628597&r2=1628598&view=diff
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/JsrMetaBeanFactory.java
(original)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/JsrMetaBeanFactory.java
Wed Oct  1 04:37:36 2014
@@ -32,12 +32,15 @@ import org.apache.bval.util.AccessStrate
 import org.apache.bval.util.FieldAccess;
 import org.apache.bval.util.MethodAccess;
 import org.apache.bval.util.reflection.Reflection;
+import org.apache.commons.weaver.privilizer.Privilizing;
+import org.apache.commons.weaver.privilizer.Privilizing.CallTo;

 import javax.validation.ConstraintDeclarationException;
 import javax.validation.GroupDefinitionException;
 import javax.validation.GroupSequence;
 import javax.validation.groups.ConvertGroup;
 import javax.validation.groups.Default;
+
 import java.io.Serializable;
 import java.lang.annotation.Annotation;
 import java.lang.annotation.ElementType;
@@ -55,6 +58,7 @@ import java.util.logging.Logger;
  * Description: process the class annotations for JSR303 constraint
validations to build the MetaBean with information
  * from annotations and JSR303 constraint mappings (defined in xml)<br/>
  */
+@Privilizing(@CallTo(Reflection.class))
 public class JsrMetaBeanFactory implements MetaBeanFactory {
     /** Shared log instance */
     // of dubious utility as it's static :/
@@ -87,8 +91,8 @@ public class JsrMetaBeanFactory implemen
             processGroupSequence(beanClass, metabean);

             // process class, superclasses and interfaces
-            List<Class<?>> classSequence = new ArrayList<Class<?>>();
-            ClassHelper.fillFullClassHierarchyAsList(classSequence, beanClass);
+            final List<Class<?>> classSequence =
+                ClassHelper.fillFullClassHierarchyAsList(new
ArrayList<Class<?>>(), beanClass);

             // start with superclasses and go down the hierarchy so that
             // the child classes are processed last to have the chance to
@@ -126,7 +130,7 @@ public class JsrMetaBeanFactory implemen

         final Collection<String> missingValid = new ArrayList<String>();

-        final Field[] fields =
Reflection.INSTANCE.getDeclaredFields(beanClass);
+        final Field[] fields = Reflection.getDeclaredFields(beanClass);
         for (final Field field : fields) {
             MetaProperty metaProperty = metabean.getProperty(field.getName());
             // create a property for those fields for which there is not yet a
@@ -147,7 +151,7 @@ public class JsrMetaBeanFactory implemen
                 }
             }
         }
-        final Method[] methods =
Reflection.INSTANCE.getDeclaredMethods(beanClass);
+        final Method[] methods = Reflection.getDeclaredMethods(beanClass);
         for (final Method method : methods) {
             if (method.isSynthetic() || method.isBridge()) {
                 continue;

Modified: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/resolver/DefaultTraversableResolver.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/resolver/DefaultTraversableResolver.java?rev=1628598&r1=1628597&r2=1628598&view=diff
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/resolver/DefaultTraversableResolver.java
(original)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/resolver/DefaultTraversableResolver.java
Wed Oct  1 04:37:36 2014
@@ -18,14 +18,18 @@ package org.apache.bval.jsr.resolver;

 import org.apache.bval.util.reflection.Reflection;
 import org.apache.commons.lang3.ClassUtils;
+import org.apache.commons.weaver.privilizer.Privilizing;
+import org.apache.commons.weaver.privilizer.Privilizing.CallTo;

 import javax.validation.Path;
 import javax.validation.TraversableResolver;
+
 import java.lang.annotation.ElementType;
 import java.util.logging.Level;
 import java.util.logging.Logger;

 /** @see javax.validation.TraversableResolver */
+@Privilizing(@CallTo(Reflection.class))
 public class DefaultTraversableResolver implements
TraversableResolver, CachingRelevant {
     private static final Logger log =
Logger.getLogger(DefaultTraversableResolver.class.getName());
     private static final boolean LOG_FINEST = log.isLoggable(Level.FINEST);
@@ -71,9 +75,9 @@ public class DefaultTraversableResolver
     /** Tries to load detect and load JPA. */
     @SuppressWarnings("unchecked")
     private void initJpa() {
-        final ClassLoader classLoader = getClassLoader();
+        final ClassLoader classLoader =
Reflection.getClassLoader(DefaultTraversableResolver.class);
         try {
-            Reflection.INSTANCE.getClass(classLoader,
PERSISTENCE_UTIL_CLASSNAME);
+            Reflection.getClass(classLoader, PERSISTENCE_UTIL_CLASSNAME);
             if (LOG_FINEST) {
                 log.log(Level.FINEST, String.format("Found %s on
classpath.", PERSISTENCE_UTIL_CLASSNAME));
             }
@@ -101,9 +105,4 @@ public class DefaultTraversableResolver
     public boolean needsCaching() {
         return jpaTR != null && CachingTraversableResolver.needsCaching(jpaTR);
     }
-
-    private static ClassLoader getClassLoader()
-    {
-      return Reflection.INSTANCE.getClassLoader(DefaultTraversableResolver.class);
-    }
 }

Modified: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/util/ClassHelper.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/util/ClassHelper.java?rev=1628598&r1=1628597&r2=1628598&view=diff
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/util/ClassHelper.java
(original)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/util/ClassHelper.java
Wed Oct  1 04:37:36 2014
@@ -43,6 +43,7 @@ public class ClassHelper {
      *            The current list of classes in the hierarchy.
      * @param clazz
      */
+    @Deprecated
     static public List<Class<?>>
fillFullClassHierarchyAsList(List<Class<?>> allClasses, Class<?>
clazz) {
         if (clazz == null || clazz == Object.class || clazz ==
Serializable.class || clazz == Cloneable.class) {
             return allClasses;
@@ -58,26 +59,4 @@ public class ClassHelper {
         return allClasses;
     }

-    /**
-     * @deprecated Will be removed for security reasons.
-     *
-     * Perform ClassUtils.getClass functions with Java 2 Security enabled.
-     */
-    @Deprecated
-    public static Class<?> getClass(String className) throws
ClassNotFoundException {
-        return getClass(className, true);
-    }
-
-    /**
-     * @deprecated Will be removed for security reasons.
-     *
-     * Perform ClassUtils.getClass functions with Java 2 Security enabled.
-     */
-    @Deprecated
-    public static Class<?> getClass(String className, boolean
initialize) throws ClassNotFoundException {
-        ClassLoader loader = Thread.currentThread().getContextClassLoader();
-        if (loader == null)
-          loader = ClassHelper.class.getClassLoader();
-        return ClassUtils.getClass(loader, className, initialize);
-    }
 }

Mime
View raw message