bval-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dwo...@apache.org
Subject svn commit: r936969 - in /incubator/bval/trunk/bval-jsr303/src: main/java/org/apache/bval/jsr303/ClassValidator.java test/java/org/apache/bval/jsr303/Jsr303Test.java
Date Thu, 22 Apr 2010 17:16:49 GMT
Author: dwoods
Date: Thu Apr 22 17:16:49 2010
New Revision: 936969

URL: http://svn.apache.org/viewvc?rev=936969&view=rev
Log:
BVAL-24 IllegalArgumentException should be thrown when calling Validator.getConstraintsForClass()
with a null class.  Contributed by Carlos Vara.

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

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=936969&r1=936968&r2=936969&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
Thu Apr 22 17:16:49 2010
@@ -297,6 +297,9 @@ public class ClassValidator extends Bean
      *                             constraints are invalid.
      */
     public BeanDescriptor getConstraintsForClass(Class<?> clazz) {
+        if (clazz == null) {
+            throw new IllegalArgumentException("Class cannot be null");
+        }
         try {
             MetaBean metaBean = factoryContext.getMetaBeanFinder().findForClass(clazz);
             BeanDescriptorImpl edesc =

Modified: incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/Jsr303Test.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/Jsr303Test.java?rev=936969&r1=936968&r2=936969&view=diff
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/Jsr303Test.java
(original)
+++ incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/Jsr303Test.java
Thu Apr 22 17:16:49 2010
@@ -217,6 +217,20 @@ public class Jsr303Test extends TestCase
         Set<ConstraintViolation<SizeTestEntity>> vi = getValidator().validate(en);
         assertEquals(13, vi.size());
     }
+    
+    /**
+     * JSR-303 Section 5.1.c, IllegalArgumentException should be thrown
+     */
+    public void testGetConstraintsForNullClass() {
+        Validator validator = getValidator();
+        try {
+            validator.getConstraintsForClass(null);
+            Assert.fail("No exception thrown on Validator.getConstraintsForClass(null)");
+        } catch (IllegalArgumentException e) {
+            // Correct
+            return;
+        }
+    }
 
     private Validator getValidator() {
 //        return Validation.buildDefaultValidatorFactory().getValidator();



Mime
View raw message