This is an automated email from the ASF dual-hosted git repository.
tanxinyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ratis.git
The following commit(s) were added to refs/heads/master by this push:
new 6c761f4ce RATIS-2347. NPE in GrpcServerProtocolService. (#1304)
6c761f4ce is described below
commit 6c761f4ce87ab640c6571cbd98c7ddefe1a5e9b5
Author: Tsz-Wo Nicholas Sze <[email protected]>
AuthorDate: Sat Nov 1 07:42:17 2025 -0700
RATIS-2347. NPE in GrpcServerProtocolService. (#1304)
---
ratis-common/src/main/java/org/apache/ratis/util/ProtoUtils.java | 6 ++++++
.../org/apache/ratis/grpc/server/GrpcServerProtocolService.java | 3 +--
.../org/apache/ratis/server/impl/SnapshotInstallationHandler.java | 3 +--
3 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/ratis-common/src/main/java/org/apache/ratis/util/ProtoUtils.java
b/ratis-common/src/main/java/org/apache/ratis/util/ProtoUtils.java
index cd22ebe6b..161715bf8 100644
--- a/ratis-common/src/main/java/org/apache/ratis/util/ProtoUtils.java
+++ b/ratis-common/src/main/java/org/apache/ratis/util/ProtoUtils.java
@@ -35,6 +35,8 @@ import org.apache.ratis.protocol.RaftGroupMemberId;
import org.apache.ratis.protocol.RaftPeer;
import org.apache.ratis.protocol.RaftPeerId;
import org.apache.ratis.thirdparty.com.google.protobuf.ByteString;
+import org.apache.ratis.thirdparty.com.google.protobuf.MessageOrBuilder;
+import org.apache.ratis.thirdparty.com.google.protobuf.TextFormat;
import java.io.IOException;
import java.io.ObjectOutputStream;
@@ -250,4 +252,8 @@ public interface ProtoUtils {
+ "#" + proto.getCallId() + ":"
+ (proto.getSuccess()? "OK": "FAIL");
}
+
+ static <MESSAGE extends MessageOrBuilder> String shortDebugString(MESSAGE
message) {
+ return message != null ? TextFormat.shortDebugString(message) : "null";
+ }
}
diff --git
a/ratis-grpc/src/main/java/org/apache/ratis/grpc/server/GrpcServerProtocolService.java
b/ratis-grpc/src/main/java/org/apache/ratis/grpc/server/GrpcServerProtocolService.java
index b123c44a7..a13e74b89 100644
---
a/ratis-grpc/src/main/java/org/apache/ratis/grpc/server/GrpcServerProtocolService.java
+++
b/ratis-grpc/src/main/java/org/apache/ratis/grpc/server/GrpcServerProtocolService.java
@@ -25,7 +25,6 @@ import org.apache.ratis.server.RaftServer;
import org.apache.ratis.server.protocol.RaftServerProtocol;
import org.apache.ratis.server.util.ServerStringUtils;
import org.apache.ratis.thirdparty.com.google.protobuf.MessageOrBuilder;
-import org.apache.ratis.thirdparty.com.google.protobuf.TextFormat;
import org.apache.ratis.thirdparty.io.grpc.Status;
import org.apache.ratis.thirdparty.io.grpc.StatusRuntimeException;
import org.apache.ratis.thirdparty.io.grpc.stub.StreamObserver;
@@ -176,7 +175,7 @@ class GrpcServerProtocolService extends
RaftServerProtocolServiceImplBase {
requestFuture.get().thenAccept(reply -> {
BatchLogger.print(BatchLogKey.COMPLETED_REPLY, getName(),
suffix -> LOG.info("{}: Completed {}, lastReply: {} {}",
- getId(), op, TextFormat.shortDebugString(reply), suffix));
+ getId(), op, ProtoUtils.shortDebugString(reply), suffix));
responseObserver.onCompleted();
});
}
diff --git
a/ratis-server/src/main/java/org/apache/ratis/server/impl/SnapshotInstallationHandler.java
b/ratis-server/src/main/java/org/apache/ratis/server/impl/SnapshotInstallationHandler.java
index faefaaa38..eac690feb 100644
---
a/ratis-server/src/main/java/org/apache/ratis/server/impl/SnapshotInstallationHandler.java
+++
b/ratis-server/src/main/java/org/apache/ratis/server/impl/SnapshotInstallationHandler.java
@@ -36,7 +36,6 @@ import org.apache.ratis.server.protocol.RaftServerProtocol.Op;
import org.apache.ratis.server.protocol.TermIndex;
import org.apache.ratis.server.raftlog.LogProtoUtils;
import org.apache.ratis.server.util.ServerStringUtils;
-import org.apache.ratis.thirdparty.com.google.protobuf.TextFormat;
import org.apache.ratis.util.BatchLogger;
import org.apache.ratis.util.CodeInjectionForTesting;
import org.apache.ratis.util.LifeCycle;
@@ -145,7 +144,7 @@ class SnapshotInstallationHandler {
final LogEntryProto proto =
request.getLastRaftConfigurationLogEntryProto();
state.truncate(proto.getIndex());
if
(!state.getRaftConf().equals(LogProtoUtils.toRaftConfiguration(proto))) {
- LOG.info("{}: set new configuration {} from snapshot",
getMemberId(), TextFormat.shortDebugString(proto));
+ LOG.info("{}: set new configuration {} from snapshot",
getMemberId(), ProtoUtils.shortDebugString(proto));
state.setRaftConf(proto);
state.writeRaftConfiguration(proto);
server.getStateMachine().event().notifyConfigurationChanged(