From b8c09ea65447eca5ba6134e55f92422cd8746be4 Mon Sep 17 00:00:00 2001 From: Victor Chudnovsky Date: Thu, 30 May 2024 10:44:17 -0700 Subject: [PATCH] fix: guard against NullPointerException in mergeFields, mergeEnums --- .../discotoproto3converter/proto3/ProtoMerger.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/com/google/cloud/discotoproto3converter/proto3/ProtoMerger.java b/src/main/java/com/google/cloud/discotoproto3converter/proto3/ProtoMerger.java index 5a2964a..c04e76d 100644 --- a/src/main/java/com/google/cloud/discotoproto3converter/proto3/ProtoMerger.java +++ b/src/main/java/com/google/cloud/discotoproto3converter/proto3/ProtoMerger.java @@ -87,6 +87,11 @@ private void mergeMessages(Map newMessages, Map newMessages, Message oldMessage, Message newMessage) { + + if (newMessage == null) { + return; + } + Map newEnumsMap = new HashMap<>(); for (Message nestedEnum : newMessage.getEnums()) { newEnumsMap.put(nestedEnum.getName(), nestedEnum); @@ -99,6 +104,11 @@ private void mergeEnums( private void mergeFields( Message newMessage, Message oldMessage, Map newMessages) { + + if (newMessage == null) { + return; + } + // Merge fields Map newFieldsMap = newMessage.getFields().stream().collect(Collectors.toMap(ProtoElement::getName, f -> f));