From 9101dc1f842266522843b8aaa983d0932cb6df90 Mon Sep 17 00:00:00 2001 From: Robert Bradshaw Date: Tue, 31 Oct 2023 14:02:36 -0700 Subject: [PATCH] Avoid potential null pointer exceptions in logging. --- .../apache/beam/fn/harness/logging/BeamFnLoggingClient.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sdks/java/harness/src/main/java/org/apache/beam/fn/harness/logging/BeamFnLoggingClient.java b/sdks/java/harness/src/main/java/org/apache/beam/fn/harness/logging/BeamFnLoggingClient.java index 8fa074b04768..c16296be717d 100644 --- a/sdks/java/harness/src/main/java/org/apache/beam/fn/harness/logging/BeamFnLoggingClient.java +++ b/sdks/java/harness/src/main/java/org/apache/beam/fn/harness/logging/BeamFnLoggingClient.java @@ -408,11 +408,15 @@ public void publish(LogRecord record) { if (severity == null) { return; } + if (record == null) { + return; + } + String messageString = getFormatter().formatMessage(record); BeamFnApi.LogEntry.Builder builder = BeamFnApi.LogEntry.newBuilder() .setSeverity(severity) - .setMessage(getFormatter().formatMessage(record)) + .setMessage(messageString == null ? "null" : messageString) .setThread(Integer.toString(record.getThreadID())) .setTimestamp( Timestamp.newBuilder()