Copilot commented on code in PR #2514:
URL: https://github.com/apache/groovy/pull/2514#discussion_r3183382138
##########
src/main/java/org/codehaus/groovy/classgen/asm/sc/AbstractFunctionalInterfaceWriter.java:
##########
@@ -156,4 +179,92 @@ default Parameter prependParameter(final List<Parameter>
parameterList, final St
parameterList.add(0, parameter);
return parameter;
}
+
+ default SerializedLambdaKey createSerializedLambdaKey(final String
abstractMethodDesc, final int implMethodKind, final ClassNode implClass, final
MethodNode implMethod, final Parameter[] parameters, final ClassNode
functionalType, final MethodNode abstractMethod, final int capturedArgCount) {
+ return new SerializedLambdaKey(
+ implMethodKind,
+ getClassInternalName(implClass),
+ implMethod.getName(),
+ getMethodDescriptor(implMethod),
+ getClassInternalName(functionalType.redirect()),
+ abstractMethod.getName(),
+ abstractMethodDesc,
+ createInstantiatedMethodType(abstractMethodDesc, implMethod,
parameters).getDescriptor(),
+ capturedArgCount
+ );
+ }
+
+ default void addDeserializeLambdaDispatcherEntry(final WriterController
controller, final Parameter[] parameters, final SerializedLambdaKey key, final
MethodNode helperMethod) {
+ BlockStatement dispatcher =
getOrAddDeserializeLambdaDispatcher(controller, parameters);
+ MethodCallExpression helperCall =
callX(classX(controller.getClassNode()), helperMethod.getName(),
args(varX(parameters[0])));
+ helperCall.setImplicitThis(false);
+ helperCall.setMethodTarget(helperMethod);
+
+ List<Statement> statements = dispatcher.getStatements();
+ statements.add(statements.size() - 1,
ifS(boolX(matchesSerializedLambda(varX(parameters[0]), key)),
returnS(helperCall)));
+ }
+
+ default BlockStatement getOrAddDeserializeLambdaDispatcher(final
WriterController controller, final Parameter[] parameters) {
+ ClassNode enclosingClass = controller.getClassNode();
+ BlockStatement dispatcher =
enclosingClass.getNodeMetaData(DeserializeLambdaDispatcher.class);
+ if (dispatcher != null) {
+ return dispatcher;
+ }
+
+ dispatcher = new BlockStatement();
+
dispatcher.addStatement(returnS(callX(classX(ClassHelper.make(Objects.class)),
"requireNonNull", args(nullX(), constX("Invalid lambda deserialization")))));
+
Review Comment:
The dispatcher fallback currently does `Objects.requireNonNull(null,
"Invalid lambda deserialization")`, which will always throw a
NullPointerException. This works as a fail-fast, but it’s non-obvious and
produces an exception type/stacktrace that’s harder to diagnose. Consider
replacing this with an explicit `throw` of a more appropriate exception (e.g.,
`java.io.InvalidObjectException` or `IllegalArgumentException`) so
invalid/mismatched SerializedLambda cases are clearer.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]