Skip to content

Commit 56470f2

Browse files
committed
Contain the use of reflection in amazon-lambda
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
1 parent 14fca6b commit 56470f2

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

extensions/amazon-lambda/deployment/src/main/java/io/quarkus/amazon/lambda/deployment/AmazonLambdaProcessor.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,6 @@ List<AmazonLambdaBuildItem> discover(CombinedIndexBuildItem combinedIndexBuildIt
114114
final DotName name = info.name();
115115
final String lambda = name.toString();
116116
builder.addBeanClass(lambda);
117-
reflectiveClassBuildItemBuildProducer
118-
.produce(ReflectiveClassBuildItem.builder(lambda).methods().build());
119117

120118
String cdiName = null;
121119
AnnotationInstance named = info.declaredAnnotation(NAMED);
@@ -150,9 +148,18 @@ List<AmazonLambdaBuildItem> discover(CombinedIndexBuildItem combinedIndexBuildIt
150148
}
151149
}
152150
}
153-
current = combinedIndexBuildItem.getIndex().getClassByName(current.superName());
151+
if (!done) {
152+
current = combinedIndexBuildItem.getIndex().getClassByName(current.superName());
153+
}
154+
}
155+
if (done) {
156+
String handlerClass = current.name().toString();
157+
ret.add(new AmazonLambdaBuildItem(handlerClass, cdiName, streamHandler));
158+
reflectiveClassBuildItemBuildProducer.produce(ReflectiveClassBuildItem.builder(handlerClass).methods()
159+
.reason(getClass().getName()
160+
+ ": reflectively accessed in io.quarkus.amazon.lambda.runtime.AmazonLambdaRecorder.discoverHandlerMethod")
161+
.build());
154162
}
155-
ret.add(new AmazonLambdaBuildItem(lambda, cdiName, streamHandler));
156163
}
157164
additionalBeanBuildItemBuildProducer.produce(builder.build());
158165
reflectiveClassBuildItemBuildProducer

extensions/amazon-lambda/runtime/src/main/java/io/quarkus/amazon/lambda/runtime/AmazonLambdaRecorder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public static void handle(InputStream inputStream, OutputStream outputStream, Co
9292
}
9393

9494
private static Method discoverHandlerMethod(Class<? extends RequestHandler<?, ?>> handlerClass) {
95-
final Method[] methods = handlerClass.getMethods();
95+
final Method[] methods = handlerClass.getDeclaredMethods();
9696
Method method = null;
9797
for (int i = 0; i < methods.length && method == null; i++) {
9898
if (methods[i].getName().equals("handleRequest")) {

0 commit comments

Comments
 (0)