bval-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r1649699 - in /bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr: ConfigurationImpl.java ConstraintAnnotationAttributes.java
Date Tue, 06 Jan 2015 00:58:07 GMT
Author: mbenson
Date: Tue Jan  6 00:58:06 2015
New Revision: 1649699

URL: http://svn.apache.org/r1649699
Log:
cleanup

Modified:
    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

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=1649699&r1=1649698&r2=1649699&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
Tue Jan  6 00:58:06 2015
@@ -24,7 +24,6 @@ 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;
@@ -402,19 +401,15 @@ public class ConfigurationImpl implement
     }
 
     private ValidationProvider<?> findProvider() {
-        if (providerClass != null) {
-            for (ValidationProvider<?> provider : providerResolver
-                  .getValidationProviders()) {
-                if (providerClass.isAssignableFrom(provider.getClass())) {
-                    return provider;
-                }
+        if (providerClass == null) {
+            return providerResolver.getValidationProviders().get(0);
+        } 
+        for (ValidationProvider<?> provider : providerResolver.getValidationProviders())
{
+            if (providerClass.isAssignableFrom(provider.getClass())) {
+                return provider;
             }
-            throw new ValidationException(
-                  "Unable to find suitable provider: " + providerClass);
-        } else {
-            List<ValidationProvider<?>> providers = providerResolver.getValidationProviders();
-            return providers.get(0);
         }
+        throw new ValidationException("Unable to find suitable provider: " + providerClass);
     }
 
     /**
@@ -433,19 +428,6 @@ public class ConfigurationImpl implement
         return executableValidation;
     }
 
-    private String executableValidationTypesAsString() {
-        if (executableValidation == null || executableValidation.isEmpty()) {
-            return "";
-        }
-
-        final StringBuilder builder = new StringBuilder();
-        for (final ExecutableType type : executableValidation) {
-            builder.append(type.name()).append(",");
-        }
-        final String s = builder.toString();
-        return s.substring(0, s.length() - 1);
-    }
-
     public Closeable getClosable() {
         return new Closeable() {
             public void close() throws IOException {

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=1649699&r1=1649698&r2=1649699&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
Tue Jan  6 00:58:06 2015
@@ -18,7 +18,6 @@ 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;
 
@@ -38,6 +37,7 @@ import java.util.concurrent.ConcurrentMa
  * 
  * @version $Rev: 1165923 $ $Date: 2011-09-06 18:07:53 -0500 (Tue, 06 Sep 2011) $
  */
+@Privilizing(@CallTo(Reflection.class))
 public enum ConstraintAnnotationAttributes {
     /**
      * "message"
@@ -125,10 +125,10 @@ public enum ConstraintAnnotationAttribut
     public <V> V get(Map<? super String, ? super V> map) {
         @SuppressWarnings("unchecked")
         final V result = (V) map.get(getAttributeName());
-        if (!TypeUtils.isInstance(result, getType())) {
-            throw new IllegalStateException(String.format("Invalid '%s' value: %s", getAttributeName(),
result));
+        if (TypeUtils.isInstance(result, getType())) {
+            return result;
         }
-        return result;
+        throw new IllegalStateException(String.format("Invalid '%s' value: %s", getAttributeName(),
result));
     }
 
     public <C extends Annotation> Worker<C> analyze(final Class<C> clazz)
{
@@ -192,9 +192,6 @@ public enum ConstraintAnnotationAttribut
             if (oldMtd != null) {
                 return oldMtd;
             }
-            if (!m.isAccessible()) {
-                m.setAccessible(true);
-            }
             return m;
         }
 
@@ -208,12 +205,16 @@ public enum ConstraintAnnotationAttribut
             return result;
         }
 
-        @Privileged
         private Object doInvoke(final Annotation constraint) {
+            final boolean unset = Reflection.setAccessible(method, true);
             try {
                 return method.invoke(constraint);
             } catch (Exception e) {
                 throw new RuntimeException(e);
+            } finally {
+                if (unset) {
+                    Reflection.setAccessible(method, false);
+                }
             }
         }
     }



Mime
View raw message