-
Notifications
You must be signed in to change notification settings - Fork 3k
Contain the use of reflection in amazon-lambda #48425
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
Contain the use of reflection in amazon-lambda #48425
Conversation
Instead of registering subclasses of the class actually implementing the handler, registers the class that actually implements the handler. This way Quarkus can use `getDeclaredMethods` instead of `getMethods` at runtime, which has less coverage (it doesn't return inherited methods). Closes: quarkusio#44656
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.
Pull Request Overview
This PR updates the reflection behavior for Amazon Lambda handler discovery to limit the methods inspected and to register only the class that directly implements the handler.
- Updated reflection usage in AmazonLambdaRecorder to use getDeclaredMethods instead of getMethods.
- Adjusted AmazonLambdaProcessor to register reflective build items based on the discovered concrete handler class.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
File | Description |
---|---|
extensions/amazon-lambda/runtime/src/main/java/io/quarkus/amazon/lambda/runtime/AmazonLambdaRecorder.java | Switched from getMethods() to getDeclaredMethods() to restrict method lookup to declared methods only. |
extensions/amazon-lambda/deployment/src/main/java/io/quarkus/amazon/lambda/deployment/AmazonLambdaProcessor.java | Modified logic to register the reflective build item for the actual implementing handler class when the discovery process is complete. |
Comments suppressed due to low confidence (3)
extensions/amazon-lambda/runtime/src/main/java/io/quarkus/amazon/lambda/runtime/AmazonLambdaRecorder.java:95
- Add a comment explaining why getDeclaredMethods() is preferred over getMethods(), noting that inherited methods are intentionally excluded for performance and precision.
final Method[] methods = handlerClass.getDeclaredMethods();
extensions/amazon-lambda/deployment/src/main/java/io/quarkus/amazon/lambda/deployment/AmazonLambdaProcessor.java:151
- [nitpick] The variable name 'done' is ambiguous; consider renaming it to something more descriptive that clarifies its role in the handler discovery process.
if (!done) {
extensions/amazon-lambda/deployment/src/main/java/io/quarkus/amazon/lambda/deployment/AmazonLambdaProcessor.java:155
- [nitpick] Include an inline comment to describe the condition under which 'done' becomes true to improve code readability and maintainability.
if (done) {
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.
Let's see how it goes :)
Status for workflow
|
Instead of registering subclasses of the class actually implementing the
handler, registers the class that actually implements the handler.
This way Quarkus can use
getDeclaredMethods
instead ofgetMethods
atruntime, which has less coverage (it doesn't return inherited methods).