You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@eventmesh.apache.org by ch...@apache.org on 2022/10/25 06:48:52 UTC
[incubator-eventmesh] branch master updated: feat(#1705): add NPE exception check
This is an automated email from the ASF dual-hosted git repository.
chenguangsheng 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 b04fa5e6 feat(#1705): add NPE exception check
new fafe4ff3 Merge pull request #1831 from NewtonVan/dev-issue-1705
b04fa5e6 is described below
commit b04fa5e62d9bd3bffe09c1fc643abb1bbfe38365
Author: idi0tn3 <26...@qq.com>
AuthorDate: Tue Oct 25 12:02:23 2022 +0800
feat(#1705): add NPE exception check
- Use `Objects.requireNonNull` achieve fail fast
---
.../protocol/http/processor/SendAsyncMessageProcessor.java | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/SendAsyncMessageProcessor.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/SendAsyncMessageProcessor.java
index 5c4470e6..43b8f663 100644
--- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/SendAsyncMessageProcessor.java
+++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/SendAsyncMessageProcessor.java
@@ -170,9 +170,9 @@ public class SendAsyncMessageProcessor implements HttpRequestProcessor {
//do acl check
if (eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshServerSecurityEnable) {
String remoteAddr = RemotingHelper.parseChannelRemoteAddr(ctx.channel());
- String user = event.getExtension(ProtocolKey.ClientInstanceKey.USERNAME).toString();
- String pass = event.getExtension(ProtocolKey.ClientInstanceKey.PASSWD).toString();
- String subsystem = event.getExtension(ProtocolKey.ClientInstanceKey.SYS).toString();
+ String user = Objects.requireNonNull(event.getExtension(ProtocolKey.ClientInstanceKey.USERNAME)).toString();
+ String pass = Objects.requireNonNull(event.getExtension(ProtocolKey.ClientInstanceKey.PASSWD)).toString();
+ String subsystem = Objects.requireNonNull(event.getExtension(ProtocolKey.ClientInstanceKey.SYS)).toString();
int requestCode = Integer.parseInt(asyncContext.getRequest().getRequestCode());
try {
Acl.doAclCheckInHttpSend(remoteAddr, user, pass, subsystem, topic, requestCode);
@@ -226,12 +226,12 @@ public class SendAsyncMessageProcessor implements HttpRequestProcessor {
}
String ttl = String.valueOf(EventMeshConstants.DEFAULT_MSG_TTL_MILLS);
- if (StringUtils.isBlank(event.getExtension(SendMessageRequestBody.TTL).toString())
- && !StringUtils.isNumeric(event.getExtension(SendMessageRequestBody.TTL).toString())) {
+ if (StringUtils.isBlank(Objects.requireNonNull(event.getExtension(SendMessageRequestBody.TTL)).toString())
+ && !StringUtils.isNumeric(Objects.requireNonNull(event.getExtension(SendMessageRequestBody.TTL)).toString())) {
event = CloudEventBuilder.from(event).withExtension(SendMessageRequestBody.TTL, ttl).build();
}
- String content = new String(event.getData().toBytes(), StandardCharsets.UTF_8);
+ String content = event.getData() == null ? "" : new String(event.getData().toBytes(), StandardCharsets.UTF_8);
if (content.length() > eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshEventSize) {
httpLogger.error("Event size exceeds the limit: {}",
eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshEventSize);
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: commits-help@eventmesh.apache.org