-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Sometimes a message builder is called not as a chain of seXxx() calls but depending on some condition or within an iteration. For example:
private static <I> InboxAddresses inboxAddressesOf(Set<I> entityIds) {
var builder = InboxAddresses.newBuilder();
for (var id : entityIds) {
var packed = Identifier.pack(id);
builder.addId(packed);
}
return builder.build();
}IntelliJ IDEA highlights the call to builder.addId(packed) as the one with the ignored return value. At the time of writing, it is not possible to configure the IDEA settings so that it understands ignoring methods called on a class derived from the one specified in these settings:
Adding com.google.protobuf.Message.Builder with regex for set* and add* methods has no effect. Still, we do want to keep this inspection in IDEA and in other static code analysis tools because usually not treating a result is a mistake made by a programming in a rush. On the other hand, false alarms by IDEA and other tools unnecessary distracts the developer's attention.
To solve this issue we need to add the annotation com.google.errorprone.annotations.CanIgnoreReturnValue to all generated Builder methods that modify the state of the builder such as setXxx(), addXxx(), clearXxx(), etc.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
