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/eventmesh.git


The following commit(s) were added to refs/heads/master by this push:
     new 906fcdb09 [ISSUE #3649] Method invocation may produce 
'NullPointerException'.[CloudEventsProtocolAdaptor] (#3660)
906fcdb09 is described below

commit 906fcdb09cfd81b885d3d0f8cbb1b26a9810035b
Author: kyooosukedn <[email protected]>
AuthorDate: Thu Apr 13 08:30:03 2023 +0200

    [ISSUE #3649] Method invocation may produce 
'NullPointerException'.[CloudEventsProtocolAdaptor] (#3660)
    
    [ISSUE #3649] Method invocation may produce 
'NullPointerException'.[CloudEventsProtocolAdaptor]
---
 .../protocol/cloudevents/CloudEventsProtocolAdaptor.java         | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git 
a/eventmesh-protocol-plugin/eventmesh-protocol-cloudevents/src/main/java/org/apache/eventmesh/protocol/cloudevents/CloudEventsProtocolAdaptor.java
 
b/eventmesh-protocol-plugin/eventmesh-protocol-cloudevents/src/main/java/org/apache/eventmesh/protocol/cloudevents/CloudEventsProtocolAdaptor.java
index d3e8ce12c..43e04ea09 100644
--- 
a/eventmesh-protocol-plugin/eventmesh-protocol-cloudevents/src/main/java/org/apache/eventmesh/protocol/cloudevents/CloudEventsProtocolAdaptor.java
+++ 
b/eventmesh-protocol-plugin/eventmesh-protocol-cloudevents/src/main/java/org/apache/eventmesh/protocol/cloudevents/CloudEventsProtocolAdaptor.java
@@ -38,10 +38,10 @@ import 
org.apache.eventmesh.protocol.cloudevents.resolver.tcp.TcpMessageProtocol
 
 import org.apache.commons.lang3.StringUtils;
 
-import java.nio.charset.StandardCharsets;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 
 import io.cloudevents.CloudEvent;
 import io.cloudevents.core.format.EventFormat;
@@ -118,7 +118,7 @@ public class CloudEventsProtocolAdaptor<T extends 
ProtocolTransportObject>
     @Override
     public ProtocolTransportObject fromCloudEvent(CloudEvent cloudEvent) 
throws ProtocolHandleException {
         Preconditions.checkNotNull(cloudEvent, "cloudEvent cannot be null");
-        String protocolDesc = 
cloudEvent.getExtension(Constants.PROTOCOL_DESC).toString();
+        String protocolDesc = 
Objects.requireNonNull(cloudEvent.getExtension(Constants.PROTOCOL_DESC)).toString();
         if (StringUtils.equals("http", protocolDesc)) {
             HttpCommand httpCommand = new HttpCommand();
             Body body = new Body() {
@@ -127,8 +127,9 @@ public class CloudEventsProtocolAdaptor<T extends 
ProtocolTransportObject>
                 @Override
                 public Map<String, Object> toMap() {
                     byte[] eventByte =
-                        
EventFormatProvider.getInstance().resolveFormat(JsonFormat.CONTENT_TYPE).serialize(cloudEvent);
-                    map.put("content", new String(eventByte, 
StandardCharsets.UTF_8));
+                        
Objects.requireNonNull(EventFormatProvider.getInstance()
+                            
.resolveFormat(JsonFormat.CONTENT_TYPE)).serialize(cloudEvent);
+                    map.put("content", new String(eventByte, 
Constants.DEFAULT_CHARSET));
                     return map;
                 }
             };


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to