Support for ConstraintValidator#initialize - #89
Draft
pfichtner wants to merge 4 commits into
Draft
Conversation
Implement a static validator cache and weave initialization logic into classes using dynamic proxies and INVOKEDYNAMIC to avoid creating extra .class files.
… initialization Improve array handling in validator initialization and ensure deterministic field ordering.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds support for the ConstraintValidator#initialize lifecycle method in custom validators. This ensures that validators can correctly access annotation attributes (like min, max, or custom regex patterns) at runtime, fulfilling JSR 380 requirements while strictly adhering to the project's constraint of not creating additional class files.
Problem
Previously, vaadoo only supported validators that didn't require initialization. For validators implementing initialize(A annotation), the method was never called. This led to uninitialized fields within the validator instances, resulting in incorrect validation logic (e.g., a MinValidator always using a default threshold of 0 instead of the value specified in the annotation).
Solution: Static Validator Cache with Weaved Proxies
The implementation leverages a "self-contained" bytecode strategy that keeps the output classes 1:1 with the input classes:
the following once during class loading:
Key Changes
Verification
Technical Details