Skip to content

Commit

Permalink
[ISSUE apache#3649] Method invocation may produce 'NullPointerExcepti…
Browse files Browse the repository at this point in the history
…on'.[CloudEventsProtocolAdaptor] (apache#3660)

[ISSUE apache#3649] Method invocation may produce 'NullPointerException'.[CloudEventsProtocolAdaptor]
  • Loading branch information
kyooosukedn authored Apr 13, 2023
1 parent b07793f commit 906fcdb
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@

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;
Expand Down Expand Up @@ -118,7 +118,7 @@ public List<CloudEvent> toBatchCloudEvent(ProtocolTransportObject protocol)
@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() {
Expand All @@ -127,8 +127,9 @@ public ProtocolTransportObject fromCloudEvent(CloudEvent cloudEvent) throws Prot
@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;
}
};
Expand Down

0 comments on commit 906fcdb

Please sign in to comment.