You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@eventmesh.apache.org by mi...@apache.org on 2022/10/26 12:18:19 UTC
[incubator-eventmesh] branch master updated: [ISSUE #1894]Add NPE check
This is an automated email from the ASF dual-hosted git repository.
mikexue pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-eventmesh.git
The following commit(s) were added to refs/heads/master by this push:
new 947ef900 [ISSUE #1894]Add NPE check
new 079bd693 Merge pull request #1904 from suxusheng1992/master
947ef900 is described below
commit 947ef9009d1d64685d2b7d148ad5d0b6011aa3f3
Author: hinsonsu <hi...@163.com>
AuthorDate: Wed Oct 26 19:51:54 2022 +0800
[ISSUE #1894]Add NPE check
---
.../protocol/meshmessage/MeshMessageProtocolAdaptor.java | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/eventmesh-protocol-plugin/eventmesh-protocol-meshmessage/src/main/java/org/apache/eventmesh/protocol/meshmessage/MeshMessageProtocolAdaptor.java b/eventmesh-protocol-plugin/eventmesh-protocol-meshmessage/src/main/java/org/apache/eventmesh/protocol/meshmessage/MeshMessageProtocolAdaptor.java
index 4b6a274c..5f48d201 100644
--- a/eventmesh-protocol-plugin/eventmesh-protocol-meshmessage/src/main/java/org/apache/eventmesh/protocol/meshmessage/MeshMessageProtocolAdaptor.java
+++ b/eventmesh-protocol-plugin/eventmesh-protocol-meshmessage/src/main/java/org/apache/eventmesh/protocol/meshmessage/MeshMessageProtocolAdaptor.java
@@ -46,6 +46,7 @@ import java.util.List;
import java.util.Map;
import io.cloudevents.CloudEvent;
+import com.google.common.base.Preconditions;
public class MeshMessageProtocolAdaptor implements ProtocolAdaptor<ProtocolTransportObject> {
@@ -111,7 +112,8 @@ public class MeshMessageProtocolAdaptor implements ProtocolAdaptor<ProtocolTrans
@Override
public ProtocolTransportObject fromCloudEvent(CloudEvent cloudEvent) throws ProtocolHandleException {
- String protocolDesc = cloudEvent.getExtension(Constants.PROTOCOL_DESC).toString();
+ validateCloudEvent(cloudEvent);
+ String protocolDesc = cloudEvent.getExtension(Constants.PROTOCOL_DESC) == null ? null : cloudEvent.getExtension(Constants.PROTOCOL_DESC).toString();
if (StringUtils.equals(MeshMessageProtocolConstant.PROTOCOL_DESC_HTTP, protocolDesc)) {
HttpCommand httpCommand = new HttpCommand();
@@ -120,6 +122,9 @@ public class MeshMessageProtocolAdaptor implements ProtocolAdaptor<ProtocolTrans
@Override
public Map<String, Object> toMap() {
+ if(cloudEvent.getData() == null){
+ return map;
+ }
map.put(MeshMessageProtocolConstant.PROTOCOL_KEY_CONTENT, new String(cloudEvent.getData().toBytes(), StandardCharsets.UTF_8));
return map;
}
@@ -140,4 +145,8 @@ public class MeshMessageProtocolAdaptor implements ProtocolAdaptor<ProtocolTrans
public String getProtocolType() {
return MeshMessageProtocolConstant.PROTOCOL_NAME;
}
+
+ private void validateCloudEvent(CloudEvent cloudEvent) {
+ Preconditions.checkNotNull(cloudEvent, "CloudEvent cannot be null");
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: commits-help@eventmesh.apache.org