Skip to content
Permalink
Browse files
BVAL-168: NotEmpty validator should return false for null objects
  • Loading branch information
mbenson committed Nov 7, 2018
1 parent 9171e1c commit cd98363fcc37c526254466bfd3496edadbc6dd9c
Showing 1 changed file with 6 additions and 3 deletions.
@@ -20,20 +20,23 @@

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import javax.validation.constraints.NotEmpty;

import java.lang.reflect.Array;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
* Description: Check the non emptiness of an
* any object that has a public isEmpty():boolean or a valid toString() method
* {@link ConstraintValidator} implementation for {@link NotEmpty}.
* Additionally, check the non-emptiness of an
* any object that has a public isEmpty():boolean or a valid toString() method.
*/
public class NotEmptyValidator implements ConstraintValidator<javax.validation.constraints.NotEmpty, Object> {

@Override
public boolean isValid(Object value, ConstraintValidatorContext context) {
if (value == null) {
return true;
return false;
}
if (value.getClass().isArray()) {
return Array.getLength(value) > 0;

0 comments on commit cd98363

Please sign in to comment.