Skip to content

Commit

Permalink
fix: Handling possible NullPointerException
Browse files Browse the repository at this point in the history
  • Loading branch information
cnzakii committed May 1, 2024
1 parent 70f9892 commit 1c39e30
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.ThreadLocalRandom;
import java.util.stream.IntStream;

Expand Down Expand Up @@ -83,12 +84,12 @@ public static Package buildPackage(Object message, Command command) {
final Package msg = getPackage(command);
if (message instanceof CloudEvent) {
final CloudEvent cloudEvent = (CloudEvent) message;
Preconditions.checkNotNull(cloudEvent.getDataContentType(), "DateContentType cannot be null");
Preconditions.checkNotNull(Objects.requireNonNull(cloudEvent.getDataContentType()), "DateContentType cannot be null");
msg.getHeader().putProperty(Constants.PROTOCOL_TYPE, CLOUD_EVENTS_PROTOCOL_NAME);
msg.getHeader().putProperty(Constants.PROTOCOL_VERSION, cloudEvent.getSpecVersion().toString());
msg.getHeader().putProperty(Constants.PROTOCOL_DESC, "tcp");

final byte[] bodyByte = EventFormatProvider.getInstance().resolveFormat(cloudEvent.getDataContentType())
final byte[] bodyByte = Objects.requireNonNull(EventFormatProvider.getInstance().resolveFormat(cloudEvent.getDataContentType()))
.serialize((CloudEvent) message);
msg.setBody(bodyByte);
} else if (message instanceof EventMeshMessage) {
Expand Down

0 comments on commit 1c39e30

Please sign in to comment.