Skip to content

Fully Fix Repeatable Constraint Issues #269

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

Closed
wants to merge 12 commits into from

Conversation

SentryMan
Copy link
Collaborator

  • modify AbstractConstraintAdapter to attempt to execute all constraints instead of canceling a few when a violation is found
  • adds null safety to POJO adapter retrieval (because of the above we need to prevent the pojo adapters from accepting a null)

Fixes #266 for real this time

@SentryMan SentryMan added bug Something isn't working refactor labels Jan 28, 2025
@SentryMan SentryMan added this to the 2.6 milestone Jan 28, 2025
@SentryMan SentryMan requested a review from rob-bygrave January 28, 2025 19:16
@SentryMan SentryMan self-assigned this Jan 28, 2025
@SentryMan SentryMan enabled auto-merge (squash) January 28, 2025 19:16
@SentryMan
Copy link
Collaborator Author

@rbygrave please review and deploy an RC when you get time.

@rbygrave
Copy link
Contributor

Do you want to state where the bug was in the code? Hence the design thinking around the fix.

@@ -32,7 +32,6 @@ public final boolean validate(T value, ValidationRequest req, String propertyNam
}
if (!isValid(value)) {
req.addViolation(message, propertyName);
return false;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was the problem, validation should continue even if a violation is found

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, if so that looks more like a design issue that we need to step back and look at. I'm pondering why the issue was not solely in the andThen() processing [that didn't always execute the second validation].

Copy link
Collaborator Author

@SentryMan SentryMan Jan 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that didn't always execute the second validation

the reason is because of the above, the adapter returns false, so the after validator doesn't run

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in this way, only some after handlers would run.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's easier to see it when you debug through the code

Copy link
Collaborator Author

@SentryMan SentryMan Jan 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[and thus we return void rather than boolean that is always true].

For what purpose? Validators should have the ability to disable further validation if they want. (We can table this discussion for later though)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the use case for halting validation for NotNull and NotBlank? Hibernate doesn't do it, is there a reason for it?

preserve the existing behaviour of avaje validator,

if we're saying it's to preserve existing behavior that doesn't make sense to me as all the adapters have this halting problem and we're changing them.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why should avaje differ in this respect and prevent all custom constraints from running unlike hibernate?

This is the debate we can keep going ... in the meantime, lets merge the other PR and rollout the fix preserving the current behaviour that we have for NotBlank.

hibernate doesn't stop validation like we do ...

I knew that, but you are no seeing the consistency issue. For example, some DBMS treat NULL and empty string as the same thing - that's not per spec but that the same consistency issue in a way. I'm saying its not black and white, and that the NotBlank behaviour on avaje validator was intentional [and I'm thinking for you it was a detail that you didn't dig into].

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all the adapters have this halting problem and we're changing them.

Not ALL of them. Most of them yes but not ALL - NotNull, NotBlank, Size etc were deemed correct behaviour.

What is the use case for halting validation for NotNull

It's fairly academic, due to all the validators expecting to treat null as valid apart from NullableAdapter.

and NotBlank? Hibernate doesn't do it, is there a reason for it?

For Strings we pretty much always use NotBlank and not NotNull. For strings, the debate is if there is a semantic difference between a null string and an empty string. Technically the difference is obvious but semantically most of the time we can argue that an empty string is equivalent to "the value is absent".

It's a grey area.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fairly academic, due to all the validators expecting to treat null as valid apart from NullableAdapter.

If that's the case we should commit fully and change AbstractConstraintAdapter to return true on null.

@SentryMan SentryMan closed this Jan 29, 2025
auto-merge was automatically disabled January 29, 2025 19:06

Pull request was closed

@SentryMan SentryMan deleted the fix-repeatable branch June 14, 2025 17:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working refactor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Compilation error with multiple @Pattern annoations.
2 participants