java.lang.NullPointerException

Hibernate JIRA | Michal Gajdos | 4 years ago
tip
Your exception is missing from the Samebug knowledge base.
Here are the best solutions we found on the Internet.
Click on the to mark the helpful solution and get rewards for you help.
  1. 0

    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.

    Hibernate JIRA | 4 years ago | Michal Gajdos
    java.lang.NullPointerException
  2. 0

    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.

    Hibernate JIRA | 4 years ago | Michal Gajdos
    java.lang.NullPointerException

    Root Cause Analysis

    1. java.lang.NullPointerException

      No message provided

      at org.hibernate.validator.internal.engine.MethodValidationContext.isReturnValueValidation()
    2. Hibernate Validator Engine
      ValidatorImpl.validateParameters
      1. org.hibernate.validator.internal.engine.MethodValidationContext.isReturnValueValidation(MethodValidationContext.java:213)
      2. org.hibernate.validator.internal.engine.MethodValidationContext.createPathWithElementDescriptors(MethodValidationContext.java:130)
      3. org.hibernate.validator.internal.engine.MethodValidationContext.createConstraintViolation(MethodValidationContext.java:107)
      4. org.hibernate.validator.internal.engine.ValidationContext.createConstraintViolations(ValidationContext.java:250)
      5. org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.validateSingleConstraint(ConstraintTree.java:293)
      6. org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.validateConstraints(ConstraintTree.java:138)
      7. org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.validateConstraints(ConstraintTree.java:96)
      8. org.hibernate.validator.internal.metadata.core.MetaConstraint.validateConstraint(MetaConstraint.java:85)
      9. org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraint(ValidatorImpl.java:479)
      10. org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForDefaultGroup(ValidatorImpl.java:428)
      11. org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForCurrentGroup(ValidatorImpl.java:391)
      12. org.hibernate.validator.internal.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:343)
      13. org.hibernate.validator.internal.engine.ValidatorImpl.validateCascadedConstraint(ValidatorImpl.java:635)
      14. org.hibernate.validator.internal.engine.ValidatorImpl.validateCascadedConstraints(ValidatorImpl.java:517)
      15. org.hibernate.validator.internal.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:352)
      16. org.hibernate.validator.internal.engine.ValidatorImpl.validateCascadedConstraint(ValidatorImpl.java:635)
      17. org.hibernate.validator.internal.engine.ValidatorImpl.validateCascadedConstraints(ValidatorImpl.java:517)
      18. org.hibernate.validator.internal.engine.ValidatorImpl.validateParametersForGroup(ValidatorImpl.java:985)
      19. org.hibernate.validator.internal.engine.ValidatorImpl.validateParametersInContext(ValidatorImpl.java:891)
      20. org.hibernate.validator.internal.engine.ValidatorImpl.validateParameters(ValidatorImpl.java:238)
      21. org.hibernate.validator.internal.engine.ValidatorImpl.validateParameters(ValidatorImpl.java:207)
      21 frames