-
Notifications
You must be signed in to change notification settings - Fork 28
Rely more on AnnotedTypes in CDI Extension again #191
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
Open
jungm
wants to merge
1
commit into
master
Choose a base branch
from
223-npe-cdi-extension
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+28
−37
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK this is not needed since the model already has all methods, constructors and inherited annotations (rest looks ok)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
technically yes, but e.g. annotations on method parameters are lost if the method is being overwritten and inherited over multiple levels (see
CdiConstraintOnlyOnParentClassTest, it fails if I remove processing superclass/interfaces)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume it was copied from a tck? how do you remove the constraint if you have to respect the parent mode? Last time I checked the spec the liskov principle was enforced and a child can relax a parent constraint (not the opposite) so a not null param in an interface can be null in a class so we should really stick to CDI model and ensure parent annotations are there using CDI cause like that you can just end up in unpracticable cases no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as far as I understand the spec says: "child must not strengthen preconditions or weaken postconditions", so one must not declare constraints on parameters in an overwritten method (https://jakarta.ee/specifications/bean-validation/3.1/jakarta-validation-spec-3.1#constraintdeclarationvalidationprocess-methodlevelconstraints-inheritance)
but also: "A constraint declaration can be placed on an interface. For a given class, constraint declarations held on superclasses as well as interfaces are evaluated by the Jakarta Validation provider." (https://jakarta.ee/specifications/bean-validation/3.1/jakarta-validation-spec-3.1#constraintdeclarationvalidationprocess-inheritance)
won't that mean that constraints are always inherited? actually, I am failing to see how a subtype would even explicitly weaken preconditions, I could only find examples of strengthening postconditions in the spec
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, both parts kind of contradict themselves if I'm reading it right and in CDI integration it is worse since all the inheritance is in Annotated* model, no more in plain reflection at all so think we should exclude and challenge (if desired) this test and just not loop to parents. (likely with a comment explaining the model is not reflection based + liskov principle is the opposite of this)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO the example in the test should work:
This is also how the validation ends up working, but the algorithm in the CDI extension must IMO look at the entire type hierarchy to decide whether or not to enable the BValInterceptor. And I think it is better to have false positives than false negatives at detecting what needs the interceptor (of course the goal should be to already be 100% aligned with the spec in the algorithm in BValExtension)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is allowed and this is why we must not check the parents IMHO, what you can't relax is the returned type contract, if the result is not null then you cant return null but if you accept a not null param it is ok to accept a null param since you do not break any parent use cases, you enable more.
well there are multiple things there:
while using pure reflection it is ok-ish since everything is kind of immutable, using cdi where all the model is mutable this is very limiting to do it so I wouldn't even try
maybe worse case we use a system prop disabled by default and enabled in tck module but I would really make the extension fast, detection is already not crazy fast due to the spec rules which doesn't enforce an interceptor binding IIRC (if done it wouldn't be a real issue)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note this wasn't originally about a TCK issue but something tomee users noted; https://issues.apache.org/jira/projects/TOMEE/issues/TOMEE-4449
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe a compromise is to do it only for explicit methods and skip it intentionally for all others
so something like:
means all the totally implicit (no ValidateOnExecution) cases will be skipped as before, but also means the explicit cases will work as intended with almost no penalty
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I may add my 2 cents.
I would also interpret the spec in the same way as @rmannibucau , in essence, Liskovs Principle has to be followed and precondition weakening should be possible. Thus, for retaining an interface method constraint, the implementation also has to declare the very same constraint, otherwise its a valid constraint weakening and the parent constraint should be ignored.
The rules from §5.6.5 seem to be ambiguous or incomplete for this case, and should be clarified.
In this regard, issues like https://issues.apache.org/jira/projects/TOMEE/issues/TOMEE-4449 seem to be not-spec-compliant.
How about a configurable switch? Like already proposed in https://issues.apache.org/jira/projects/BVAL/issues/BVAL-175.
It seems like BVal considered the parent method constraints till version 2.0.2, so keeping this behaviour configurable, but have the spec compliant way as default, i.e. parent constraints are not considered to support the weakening case. Since both ways also differ in performance, a switch looks like a good compromise, so that users can choose what they prefer.