Repository navigation
Conversation
Summary of ChangesHello @kabir, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request streamlines the data conversion process between gRPC protocol buffers and domain objects by optimizing the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request aims to simplify a MapStruct mapper by replacing manual default method implementations with annotations. While this is a good goal, the refactoring unfortunately introduces functional regressions by removing critical null-safety checks that were present in the original code. This could lead to NullPointerExceptions at runtime. My review includes two high-severity comments that recommend reverting the mapping methods to their original, safer default implementations to prevent these issues.
| @Mapping(target = "name", expression = "java(ResourceNameParser.defineTaskName(domain.getParams().id()))") | ||
| io.a2a.grpc.SubscribeToTaskRequest toProto(io.a2a.spec.SubscribeToTaskRequest domain); |
There was a problem hiding this comment.
This refactoring introduces a regression. The original default method implementation correctly handled cases where domain.getParams() or domain.getParams().id() were null by returning null. This new implementation will throw a NullPointerException if domain.getParams() is null, or create an invalid resource name like "tasks/null" if id is null. To prevent this, it's safer to stick with the explicit checks in the default method.
default io.a2a.grpc.SubscribeToTaskRequest toProto(io.a2a.spec.SubscribeToTaskRequest domain) {
if (domain == null || domain.getParams() == null || domain.getParams().id() == null) {
return null;
}
return io.a2a.grpc.SubscribeToTaskRequest.newBuilder()
.setName(ResourceNameParser.defineTaskName(domain.getParams().id()))
.build();
}| /** | ||
| * Converts proto SubscribeToTaskRequest to domain SubscribeToTaskRequest. | ||
| * Extracts the task ID from the name field and creates a TaskIdParams. | ||
| * The JSONRPC envelope fields (id, jsonrpc, method) are populated with defaults by the Builder. | ||
| * | ||
| * @param proto the proto SubscribeToTaskRequest | ||
| * @return the domain SubscribeToTaskRequest | ||
| */ | ||
| default io.a2a.spec.SubscribeToTaskRequest fromProto(io.a2a.grpc.SubscribeToTaskRequest proto) { | ||
| if (proto == null || proto.getName() == null) { | ||
| return null; | ||
| } | ||
| return new io.a2a.spec.SubscribeToTaskRequest.Builder() | ||
| .params(new io.a2a.spec.TaskIdParams(ResourceNameParser.extractTaskId(proto.getName()))) | ||
| .build(); | ||
| } | ||
| @BeanMapping(builder = @Builder(buildMethod = "build")) | ||
| @Mapping(target = "params", expression = "java(new io.a2a.spec.TaskIdParams(ResourceNameParser.extractTaskId(proto.getName())))") | ||
| @Mapping(target = "id", ignore = true) // Builder sets UUID default | ||
| @Mapping(target = "jsonrpc", ignore = true) // Builder sets "2.0" default | ||
| @Mapping(target = "method", ignore = true) // Builder sets "SubscribeToTask" default | ||
| io.a2a.spec.SubscribeToTaskRequest fromProto(io.a2a.grpc.SubscribeToTaskRequest proto); |
There was a problem hiding this comment.
Similar to toProto, this mapping introduces a regression. The original code returned null if proto.getName() was null, preventing errors. This new implementation will throw a NullPointerException. It's best to revert to the safer default method implementation, including the original Javadoc.
/**
* Converts proto SubscribeToTaskRequest to domain SubscribeToTaskRequest.
* Extracts the task ID from the name field and creates a TaskIdParams.
*
* @param proto the proto SubscribeToTaskRequest
* @return the domain SubscribeToTaskRequest
*/
default io.a2a.spec.SubscribeToTaskRequest fromProto(io.a2a.grpc.SubscribeToTaskRequest proto) {
if (proto == null || proto.getName() == null) {
return null;
}
return new io.a2a.spec.SubscribeToTaskRequest.Builder()
.params(new io.a2a.spec.TaskIdParams(ResourceNameParser.extractTaskId(proto.getName())))
.build();
}|
Closing since Gemini is right, and the workarounds are ugly |
No description provided.