gemini-code-assist[bot] commented on code in PR #35865:
URL: https://github.com/apache/beam/pull/35865#discussion_r2276969734
##########
sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/pubsub/PreparePubsubWriteDoFn.java:
##########
@@ -86,7 +86,12 @@ static int validatePubsubMessageSize(PubsubMessage message,
int maxPublishBatchS
totalSize += orderingKeySize;
}
- @Nullable Map<String, String> attributes = message.getAttributeMap();
+ final @Nullable Map<String, String> attributes = message.getAttributeMap();
+ if (message.getPayload().length == 0 && (attributes == null ||
attributes.isEmpty())) {
+ throw new IllegalArgumentException(
+ "Pubsub message must contain a non-empty payload or at least one
attribute. ");
+ }
Review Comment:

For better readability and to avoid a repeated method call, you can use the
`payloadSize` variable that is already available from line 64.
Also, the exception message has a trailing space which can be removed for
consistency.
```suggestion
if (payloadSize == 0 && (attributes == null || attributes.isEmpty())) {
throw new IllegalArgumentException(
"Pubsub message must contain a non-empty payload or at least one
attribute.");
}
```
--
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]