bval-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r992329 - in /incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303: ApacheValidatorFactory.java ClassValidator.java
Date Fri, 03 Sep 2010 15:33:26 GMT
Author: mbenson
Date: Fri Sep  3 15:33:26 2010
New Revision: 992329

URL: http://svn.apache.org/viewvc?rev=992329&view=rev
Log:
improve unwrap method:  narrow the application of the SuppressWarnings annotations and be
sure that discovered -Impl classes are actually assignable to the requested type.

Modified:
    incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/ApacheValidatorFactory.java
    incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/ClassValidator.java

Modified: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/ApacheValidatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/ApacheValidatorFactory.java?rev=992329&r1=992328&r2=992329&view=diff
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/ApacheValidatorFactory.java
(original)
+++ incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/ApacheValidatorFactory.java
Fri Sep  3 15:33:26 2010
@@ -207,16 +207,22 @@ public class ApacheValidatorFactory impl
     @SuppressWarnings("unchecked")
     public <T> T unwrap(Class<T> type) {
         if (type.isInstance(this)) {
-            return (T) this;
+            @SuppressWarnings("unchecked")
+            final T result = (T) this;
+            return result;
         } else if (!type.isInterface()) {
             return SecureActions.newInstance(type);
         } else {
             try {
-                Class<T> cls = ClassUtils.getClass(type.getName() + "Impl");
-                return SecureActions.newInstance(cls);
+                Class<?> cls = ClassUtils.getClass(type.getName() + "Impl");
+                if (type.isAssignableFrom(cls)) {
+                    @SuppressWarnings("unchecked")
+                    final Class<? extends T> implClass = (Class<? extends T>)
cls;
+                    return SecureActions.newInstance(implClass);
+                }
             } catch (ClassNotFoundException e) {
-                throw new ValidationException("Type " + type + " not supported");
             }
+            throw new ValidationException("Type " + type + " not supported");
         }
     }
 

Modified: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/ClassValidator.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/ClassValidator.java?rev=992329&r1=992328&r2=992329&view=diff
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/ClassValidator.java
(original)
+++ incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/ClassValidator.java
Fri Sep  3 15:33:26 2010
@@ -354,22 +354,27 @@ public class ClassValidator implements V
    * @throws ValidationException
    *             if the provider does not support the call.
    */
-  @SuppressWarnings("unchecked")
   // @Override - not allowed in 1.5 for Interface methods
   public <T> T unwrap(Class<T> type) {
     if (type.isAssignableFrom(getClass())) {
-      return (T) this;
+      @SuppressWarnings("unchecked")
+      final T result = (T) this;
+      return result;
     } else if (!type.isInterface()) {
       return SecureActions.newInstance(type, new Class[]{ApacheFactoryContext.class},
           new Object[]{factoryContext});
     } else {
       try {
-        Class<T> cls = ClassUtils.getClass(type.getName() + "Impl");
-        return SecureActions.newInstance(cls,
-            new Class[]{ApacheFactoryContext.class}, new Object[]{factoryContext});
+        Class<?> cls = ClassUtils.getClass(type.getName() + "Impl");
+        if (type.isAssignableFrom(cls)) {
+          @SuppressWarnings("unchecked")
+          final Class<? extends T> implClass = (Class<? extends T>) cls;
+          return SecureActions.newInstance(implClass,
+              new Class[]{ApacheFactoryContext.class}, new Object[]{factoryContext});
+        }
       } catch (ClassNotFoundException e) {
-        throw new ValidationException("Type " + type + " not supported");
       }
+      throw new ValidationException("Type " + type + " not supported");
     }
   }
   



Mime
View raw message