java.lang.NullPointerException

There are no available Samebug tips for this exception. Do you have an idea how to solve this issue? A short tip would help users who saw this issue last week.

  • Constraint: {code} @NotNull @Constraint(validatedBy = OneContact.Validator.class) @Retention(RetentionPolicy.RUNTIME) public @interface OneContact { String message() default "none or more than one contact"; Class<?>[] groups() default {}; Class<? extends Payload>[] payload() default {}; public class Validator implements ConstraintValidator<OneContact, Bean> { @Override public void initialize(final OneContact nonRecursive) { } @Override public boolean isValid(final Bean validationBean, final ConstraintValidatorContext constraintValidatorContext) { if (bean.getEmail() == null && bean.getPhone() == null) { return false; } return bean.getEmail() != null || bean.getPhone() != null; } } } {code} Bean: {code} @OneContact public class Bean { @Email(regexp = "[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,4}") private String email; @Pattern(regexp = "[0-9]{3,9}") private String phone; public String getEmail() { return email; } public void setEmail(final String email) { this.email = email; } public String getPhone() { return phone; } public void setPhone(final String phone) { this.phone = phone; } } {code} Business method: {code} public void validateValidBeanParamConstraint(@Valid final Bean bean) { // ... } {code} Invoke validation: {code} final ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory(); final MethodValidator methodValidator = validatorFactory.getValidator().forMethods(); methodValidator.validateParameters(businessObject, businessMethod, new Bean()); {code} throws: {code} java.lang.NullPointerException at org.hibernate.validator.internal.engine.MethodValidationContext.isReturnValueValidation(MethodValidationContext.java:213) at org.hibernate.validator.internal.engine.MethodValidationContext.createPathWithElementDescriptors(MethodValidationContext.java:130) at org.hibernate.validator.internal.engine.MethodValidationContext.createConstraintViolation(MethodValidationContext.java:107) at org.hibernate.validator.internal.engine.ValidationContext.createConstraintViolations(ValidationContext.java:250) at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.validateSingleConstraint(ConstraintTree.java:293) at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.validateConstraints(ConstraintTree.java:138) at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.validateConstraints(ConstraintTree.java:96) at org.hibernate.validator.internal.metadata.core.MetaConstraint.validateConstraint(MetaConstraint.java:85) at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraint(ValidatorImpl.java:479) at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForDefaultGroup(ValidatorImpl.java:428) at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForCurrentGroup(ValidatorImpl.java:391) at org.hibernate.validator.internal.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:343) at org.hibernate.validator.internal.engine.ValidatorImpl.validateCascadedConstraint(ValidatorImpl.java:635) at org.hibernate.validator.internal.engine.ValidatorImpl.validateCascadedConstraints(ValidatorImpl.java:517) at org.hibernate.validator.internal.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:352) at org.hibernate.validator.internal.engine.ValidatorImpl.validateCascadedConstraint(ValidatorImpl.java:635) at org.hibernate.validator.internal.engine.ValidatorImpl.validateCascadedConstraints(ValidatorImpl.java:517) at org.hibernate.validator.internal.engine.ValidatorImpl.validateParametersForGroup(ValidatorImpl.java:985) at org.hibernate.validator.internal.engine.ValidatorImpl.validateParametersInContext(ValidatorImpl.java:891) at org.hibernate.validator.internal.engine.ValidatorImpl.validateParameters(ValidatorImpl.java:238) at org.hibernate.validator.internal.engine.ValidatorImpl.validateParameters(ValidatorImpl.java:207) {code} When {{@OneContact}} is removed from {{Bean}} the problem goes away.
    via by Michal Gajdos,
  • Constraint: {code} @NotNull @Constraint(validatedBy = OneContact.Validator.class) @Retention(RetentionPolicy.RUNTIME) public @interface OneContact { String message() default "none or more than one contact"; Class<?>[] groups() default {}; Class<? extends Payload>[] payload() default {}; public class Validator implements ConstraintValidator<OneContact, Bean> { @Override public void initialize(final OneContact nonRecursive) { } @Override public boolean isValid(final Bean validationBean, final ConstraintValidatorContext constraintValidatorContext) { if (bean.getEmail() == null && bean.getPhone() == null) { return false; } return bean.getEmail() != null || bean.getPhone() != null; } } } {code} Bean: {code} @OneContact public class Bean { @Email(regexp = "[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,4}") private String email; @Pattern(regexp = "[0-9]{3,9}") private String phone; public String getEmail() { return email; } public void setEmail(final String email) { this.email = email; } public String getPhone() { return phone; } public void setPhone(final String phone) { this.phone = phone; } } {code} Business method: {code} public void validateValidBeanParamConstraint(@Valid final Bean bean) { // ... } {code} Invoke validation: {code} final ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory(); final MethodValidator methodValidator = validatorFactory.getValidator().forMethods(); methodValidator.validateParameters(businessObject, businessMethod, new Bean()); {code} throws: {code} java.lang.NullPointerException at org.hibernate.validator.internal.engine.MethodValidationContext.isReturnValueValidation(MethodValidationContext.java:213) at org.hibernate.validator.internal.engine.MethodValidationContext.createPathWithElementDescriptors(MethodValidationContext.java:130) at org.hibernate.validator.internal.engine.MethodValidationContext.createConstraintViolation(MethodValidationContext.java:107) at org.hibernate.validator.internal.engine.ValidationContext.createConstraintViolations(ValidationContext.java:250) at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.validateSingleConstraint(ConstraintTree.java:293) at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.validateConstraints(ConstraintTree.java:138) at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.validateConstraints(ConstraintTree.java:96) at org.hibernate.validator.internal.metadata.core.MetaConstraint.validateConstraint(MetaConstraint.java:85) at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraint(ValidatorImpl.java:479) at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForDefaultGroup(ValidatorImpl.java:428) at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForCurrentGroup(ValidatorImpl.java:391) at org.hibernate.validator.internal.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:343) at org.hibernate.validator.internal.engine.ValidatorImpl.validateCascadedConstraint(ValidatorImpl.java:635) at org.hibernate.validator.internal.engine.ValidatorImpl.validateCascadedConstraints(ValidatorImpl.java:517) at org.hibernate.validator.internal.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:352) at org.hibernate.validator.internal.engine.ValidatorImpl.validateCascadedConstraint(ValidatorImpl.java:635) at org.hibernate.validator.internal.engine.ValidatorImpl.validateCascadedConstraints(ValidatorImpl.java:517) at org.hibernate.validator.internal.engine.ValidatorImpl.validateParametersForGroup(ValidatorImpl.java:985) at org.hibernate.validator.internal.engine.ValidatorImpl.validateParametersInContext(ValidatorImpl.java:891) at org.hibernate.validator.internal.engine.ValidatorImpl.validateParameters(ValidatorImpl.java:238) at org.hibernate.validator.internal.engine.ValidatorImpl.validateParameters(ValidatorImpl.java:207) {code} When {{@OneContact}} is removed from {{Bean}} the problem goes away.
    via by Michal Gajdos,
    • java.lang.NullPointerException at org.hibernate.validator.internal.engine.MethodValidationContext.isReturnValueValidation(MethodValidationContext.java:213) at org.hibernate.validator.internal.engine.MethodValidationContext.createPathWithElementDescriptors(MethodValidationContext.java:130) at org.hibernate.validator.internal.engine.MethodValidationContext.createConstraintViolation(MethodValidationContext.java:107) at org.hibernate.validator.internal.engine.ValidationContext.createConstraintViolations(ValidationContext.java:250) at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.validateSingleConstraint(ConstraintTree.java:293) at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.validateConstraints(ConstraintTree.java:138) at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.validateConstraints(ConstraintTree.java:96) at org.hibernate.validator.internal.metadata.core.MetaConstraint.validateConstraint(MetaConstraint.java:85) at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraint(ValidatorImpl.java:479) at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForDefaultGroup(ValidatorImpl.java:428) at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForCurrentGroup(ValidatorImpl.java:391) at org.hibernate.validator.internal.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:343) at org.hibernate.validator.internal.engine.ValidatorImpl.validateCascadedConstraint(ValidatorImpl.java:635) at org.hibernate.validator.internal.engine.ValidatorImpl.validateCascadedConstraints(ValidatorImpl.java:517) at org.hibernate.validator.internal.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:352) at org.hibernate.validator.internal.engine.ValidatorImpl.validateCascadedConstraint(ValidatorImpl.java:635) at org.hibernate.validator.internal.engine.ValidatorImpl.validateCascadedConstraints(ValidatorImpl.java:517) at org.hibernate.validator.internal.engine.ValidatorImpl.validateParametersForGroup(ValidatorImpl.java:985) at org.hibernate.validator.internal.engine.ValidatorImpl.validateParametersInContext(ValidatorImpl.java:891) at org.hibernate.validator.internal.engine.ValidatorImpl.validateParameters(ValidatorImpl.java:238) at org.hibernate.validator.internal.engine.ValidatorImpl.validateParameters(ValidatorImpl.java:207)
    No Bugmate found.