From 776b3a8b11fd243d709ef726ac963aa7d42e532e Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Thu, 31 Jan 2019 10:05:59 -0800 Subject: [PATCH] Fixed infinite recursion problem with Java GeneratedMessageV3 (#5657) GeneratedMessageV3#setUnknownFieldsProto3 was trying to delegate to setUnknownFields but was inadvertently resulting in infinite recursion. This commit makes setUnknownFields and setUnknownFieldsProto3 delegate to a common private method to fix the problem and avoid confusion. --- .../com/google/protobuf/GeneratedMessageV3.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/java/core/src/main/java/com/google/protobuf/GeneratedMessageV3.java b/java/core/src/main/java/com/google/protobuf/GeneratedMessageV3.java index cacfa05c05a7..03eb8034e7ba 100644 --- a/java/core/src/main/java/com/google/protobuf/GeneratedMessageV3.java +++ b/java/core/src/main/java/com/google/protobuf/GeneratedMessageV3.java @@ -710,19 +710,23 @@ public BuilderType addRepeatedField(final FieldDescriptor field, final Object va return (BuilderType) this; } - @Override - public BuilderType setUnknownFields(final UnknownFieldSet unknownFields) { + private BuilderType setUnknownFieldsInternal(final UnknownFieldSet unknownFields) { this.unknownFields = unknownFields; onChanged(); return (BuilderType) this; } + @Override + public BuilderType setUnknownFields(final UnknownFieldSet unknownFields) { + return setUnknownFieldsInternal(unknownFields); + } + /** - * Delegates to setUnknownFields. This method is obsolete, but we must retain it for - * compatibility with older generated code. + * This method is obsolete, but we must retain it for compatibility with + * older generated code. */ protected BuilderType setUnknownFieldsProto3(final UnknownFieldSet unknownFields) { - return setUnknownFields(unknownFields); + return setUnknownFieldsInternal(unknownFields); } @Override