Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE #3649] Method invocation may produce 'NullPointerException'.[CloudEventsProtocolAdaptor] #3660

Merged
merged 3 commits into from
Apr 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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