Skip to content

Commit 6c761f4

Browse files
authored
RATIS-2347. NPE in GrpcServerProtocolService. (#1304)
1 parent b663b13 commit 6c761f4

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

ratis-common/src/main/java/org/apache/ratis/util/ProtoUtils.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
import org.apache.ratis.protocol.RaftPeer;
3636
import org.apache.ratis.protocol.RaftPeerId;
3737
import org.apache.ratis.thirdparty.com.google.protobuf.ByteString;
38+
import org.apache.ratis.thirdparty.com.google.protobuf.MessageOrBuilder;
39+
import org.apache.ratis.thirdparty.com.google.protobuf.TextFormat;
3840

3941
import java.io.IOException;
4042
import java.io.ObjectOutputStream;
@@ -250,4 +252,8 @@ static String toString(RaftRpcReplyProto proto) {
250252
+ "#" + proto.getCallId() + ":"
251253
+ (proto.getSuccess()? "OK": "FAIL");
252254
}
255+
256+
static <MESSAGE extends MessageOrBuilder> String shortDebugString(MESSAGE message) {
257+
return message != null ? TextFormat.shortDebugString(message) : "null";
258+
}
253259
}

ratis-grpc/src/main/java/org/apache/ratis/grpc/server/GrpcServerProtocolService.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import org.apache.ratis.server.protocol.RaftServerProtocol;
2626
import org.apache.ratis.server.util.ServerStringUtils;
2727
import org.apache.ratis.thirdparty.com.google.protobuf.MessageOrBuilder;
28-
import org.apache.ratis.thirdparty.com.google.protobuf.TextFormat;
2928
import org.apache.ratis.thirdparty.io.grpc.Status;
3029
import org.apache.ratis.thirdparty.io.grpc.StatusRuntimeException;
3130
import org.apache.ratis.thirdparty.io.grpc.stub.StreamObserver;
@@ -176,7 +175,7 @@ public void onCompleted() {
176175
requestFuture.get().thenAccept(reply -> {
177176
BatchLogger.print(BatchLogKey.COMPLETED_REPLY, getName(),
178177
suffix -> LOG.info("{}: Completed {}, lastReply: {} {}",
179-
getId(), op, TextFormat.shortDebugString(reply), suffix));
178+
getId(), op, ProtoUtils.shortDebugString(reply), suffix));
180179
responseObserver.onCompleted();
181180
});
182181
}

ratis-server/src/main/java/org/apache/ratis/server/impl/SnapshotInstallationHandler.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import org.apache.ratis.server.protocol.TermIndex;
3737
import org.apache.ratis.server.raftlog.LogProtoUtils;
3838
import org.apache.ratis.server.util.ServerStringUtils;
39-
import org.apache.ratis.thirdparty.com.google.protobuf.TextFormat;
4039
import org.apache.ratis.util.BatchLogger;
4140
import org.apache.ratis.util.CodeInjectionForTesting;
4241
import org.apache.ratis.util.LifeCycle;
@@ -145,7 +144,7 @@ private InstallSnapshotReplyProto installSnapshotImpl(InstallSnapshotRequestProt
145144
final LogEntryProto proto = request.getLastRaftConfigurationLogEntryProto();
146145
state.truncate(proto.getIndex());
147146
if (!state.getRaftConf().equals(LogProtoUtils.toRaftConfiguration(proto))) {
148-
LOG.info("{}: set new configuration {} from snapshot", getMemberId(), TextFormat.shortDebugString(proto));
147+
LOG.info("{}: set new configuration {} from snapshot", getMemberId(), ProtoUtils.shortDebugString(proto));
149148
state.setRaftConf(proto);
150149
state.writeRaftConfiguration(proto);
151150
server.getStateMachine().event().notifyConfigurationChanged(

0 commit comments

Comments
 (0)