diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/common/MessageUtils.java b/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/common/MessageUtils.java index 2232e539c9..a12436e330 100644 --- a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/common/MessageUtils.java +++ b/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/common/MessageUtils.java @@ -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; @@ -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) {