-
Notifications
You must be signed in to change notification settings - Fork 3k
Fix decorator abstract methods validation to match CDI specification #51439
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
base: main
Are you sure you want to change the base?
Fix decorator abstract methods validation to match CDI specification #51439
Conversation
| * Checks if a method belongs to any of the decorated types. | ||
| * A method belongs to a decorated type if it has the same name and parameter types. | ||
| */ | ||
| private static boolean belongsToDecoratedType(MethodInfo method, Set<Type> decoratedTypes, |
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 method is incorrect, because it ignores methods inherited from superinterfaces of decorated types.
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 should be relatively easy to fix.
| /** | ||
| * Checks if two methods have matching parameter types. | ||
| */ | ||
| private static boolean methodParametersMatch(MethodInfo method1, MethodInfo method2) { |
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 method is incorrect, because it ignores generic interfaces and decorators implementing instantiations of them.
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 can actually be fairly hard to fix. I know we have utilities in ArC to do type parameter substitutions, but I'm not sure how easily they apply here.
|
Also, this is completely lacking tests. |
The check for abstract methods in decorators was too restrictive. According to the CDI specification, decorators may declare abstract methods that belong to decorated types. The check should only reject abstract methods that do not belong to any decorated type. Changes: - Modified Decorators.createDecorator() to check if abstract methods belong to decorated types before rejecting them - Added methodExistsInHierarchy() to verify if a method exists in the decorated type hierarchy (including superinterfaces) - Added allParamsMatch() helper to compare method signatures - Now checks abstract methods from decorator class and inherited from superclasses (as mentioned in the TODO comment) - Added comprehensive test cases for the fix This fixes the issue where decorators with abstract methods that belong to the decorated interface were incorrectly rejected. Note: This fix does not handle generic interfaces with type parameters (e.g., GenericInterface<T> with T resolved to String). This is a known limitation that could be addressed in a follow-up PR. Fixes: quarkusio#51196
a7ec8d6 to
6c58e91
Compare
The current check for abstract methods in decorators was too restrictive. According to the CDI specification, decorators may declare abstract methods that belong to decorated types. The check should only reject abstract methods that do not belong to any decorated type.
Changes:
This fixes the issue where decorators with abstract methods that belong to the decorated interface were incorrectly rejected.