Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ConstraintExceptionHandler should skip null node when building message #298

Closed
FrogDevelopper opened this issue Jan 26, 2024 · 1 comment

Comments

@FrogDevelopper
Copy link
Contributor

Expected Behavior

The error message should be correctly constructed without null add to path

Actual Behaviour

When building the message, the path is append in the beginning to add context.
But if last node (type = BEAN) is undefined (name is null), we have a message "my_class.null: my_message"

Steps To Reproduce

  1. Create an annotation @Toto
@Documented
@Target({ TYPE })
@Retention(RUNTIME)
@Constraint(validatedBy = { TotoValidator.class })
public @interface Toto {
}
  1. Create the validator class
@Singleton
@Introspected
public class TotoValidator implements ConstraintValidator<Toto, MyClass> {

    @Override
    public boolean isValid(final MyClass myClass, @NonNull final AnnotationValue<Toto> annotationMetadata,
            @NonNull final ConstraintValidatorContext context) {
        context.messageTemplate("my_message");
        return false;
    }
}
  1. Annotate a class with it
  2. Try to validate an instance of the class
  3. See in ConstraintExceptionHandler that the last node used for building message will return null for the name leading to message ""myClass.null: my_message"

Environment Information

  • OS: MacOS 13.6.3
  • JDK: Java 17 Temurin

Example Application

No response

Version

4.2.0

@FrogDevelopper
Copy link
Contributor Author

FYI, in the ConstraintValidator, context.currentPath.nodes[2] (ValidationPath$DefaultBeanNode) already have its name as null

@FrogDevelopper FrogDevelopper changed the title ConstraintExceptionHandler should not skip null node when building message ConstraintExceptionHandler should skip null node when building message Jan 26, 2024
dstepanov pushed a commit that referenced this issue Jan 30, 2024
…path (#298) (#300)

Co-authored-by: Le Gall, Benoit <benoit.legall@rakuten.com>
sdelamo pushed a commit that referenced this issue Jan 30, 2024
…path (#298) (#300)

Co-authored-by: Le Gall, Benoit <benoit.legall@rakuten.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant