bval-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r1643453 - /bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/xml/AnnotationProxyBuilder.java
Date Fri, 05 Dec 2014 22:17:18 GMT
Author: mbenson
Date: Fri Dec  5 22:17:18 2014
New Revision: 1643453

URL: http://svn.apache.org/r1643453
Log:
clean up when we alter accessibility of members; consolidate catch constructs

Modified:
    bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/xml/AnnotationProxyBuilder.java

Modified: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/xml/AnnotationProxyBuilder.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/xml/AnnotationProxyBuilder.java?rev=1643453&r1=1643452&r2=1643453&view=diff
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/xml/AnnotationProxyBuilder.java
(original)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/xml/AnnotationProxyBuilder.java
Fri Dec  5 22:17:18 2014
@@ -30,7 +30,6 @@ import javax.validation.groups.ConvertGr
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
 import java.util.HashMap;
@@ -42,8 +41,7 @@ import java.util.concurrent.ConcurrentMa
  * Description: Holds the information and creates an annotation proxy during xml
  * parsing of validation mapping constraints. <br/>
  */
-// TODO move this guy up to org.apache.bval.jsr or
-// org.apache.bval.jsr.model
+// TODO move this guy up to org.apache.bval.jsr or org.apache.bval.jsr.model
 @Privilizing(@CallTo(Reflection.class))
 final public class AnnotationProxyBuilder<A extends Annotation> {
     private static final ConcurrentMap<Class<?>, Method[]> METHODS_CACHE = new
ConcurrentHashMap<Class<?>, Method[]>();
@@ -101,19 +99,16 @@ final public class AnnotationProxyBuilde
         this((Class<A>) annot.annotationType());
         // Obtain the "elements" of the annotation
         for (Method m : methods) {
-            if (!m.isAccessible()) {
-                m.setAccessible(true);
-            }
+            final boolean mustUnset = Reflection.setAccessible(m, true);
             try {
                 Object value = m.invoke(annot);
                 this.elements.put(m.getName(), value);
-            } catch (IllegalArgumentException e) {
-                // No args, so should not happen
-                throw new ValidationException("Cannot access annotation " + annot + " element:
" + m.getName());
-            } catch (IllegalAccessException e) {
-                throw new ValidationException("Cannot access annotation " + annot + " element:
" + m.getName());
-            } catch (InvocationTargetException e) {
-                throw new ValidationException("Cannot access annotation " + annot + " element:
" + m.getName());
+            } catch (Exception e) {
+                throw new ValidationException("Cannot access annotation " + annot + " element:
" + m.getName(), e);
+            } finally {
+                if (mustUnset) {
+                    Reflection.setAccessible(m, false);
+                }
             }
         }
     }



Mime
View raw message