From 6cf86ac37a77a7e94634b2d085737d97186befb5 Mon Sep 17 00:00:00 2001 From: theodorerose Date: Mon, 11 Jul 2022 15:02:06 +0000 Subject: [PATCH] Sync from Piper @460213275 PROTOBUF_SYNC_PIPER --- .../java/com/google/protobuf/Internal.java | 5 +++++ .../google/protobuf/RepeatedFieldBuilder.java | 4 ++++ .../protobuf/RepeatedFieldBuilderV3.java | 4 ++++ .../google/protobuf/SingleFieldBuilder.java | 3 +++ .../google/protobuf/SingleFieldBuilderV3.java | 3 +++ .../protobuf/SingleFieldBuilderV3Test.java | 2 +- .../google/protobuf/TestBadIdentifiers.java | 2 +- .../com/google/protobuf/TextFormatTest.java | 1 + src/google/protobuf/compiler/cpp/message.cc | 2 +- .../protobuf/util/json_format_proto3.proto | 5 +++++ src/google/protobuf/util/json_util_test.cc | 18 ++++++++++++++++++ 11 files changed, 46 insertions(+), 3 deletions(-) diff --git a/java/core/src/main/java/com/google/protobuf/Internal.java b/java/core/src/main/java/com/google/protobuf/Internal.java index b6bbcb160d..0fb934f9e3 100644 --- a/java/core/src/main/java/com/google/protobuf/Internal.java +++ b/java/core/src/main/java/com/google/protobuf/Internal.java @@ -600,6 +600,7 @@ public final class Internal { void addInt(int element); /** Like {@link #set(int, Object)} but more efficient in that it doesn't box the element. */ + @CanIgnoreReturnValue int setInt(int index, int element); /** Returns a mutable clone of this list with the specified capacity. */ @@ -620,6 +621,7 @@ public final class Internal { void addBoolean(boolean element); /** Like {@link #set(int, Object)} but more efficient in that it doesn't box the element. */ + @CanIgnoreReturnValue boolean setBoolean(int index, boolean element); /** Returns a mutable clone of this list with the specified capacity. */ @@ -640,6 +642,7 @@ public final class Internal { void addLong(long element); /** Like {@link #set(int, Object)} but more efficient in that it doesn't box the element. */ + @CanIgnoreReturnValue long setLong(int index, long element); /** Returns a mutable clone of this list with the specified capacity. */ @@ -660,6 +663,7 @@ public final class Internal { void addDouble(double element); /** Like {@link #set(int, Object)} but more efficient in that it doesn't box the element. */ + @CanIgnoreReturnValue double setDouble(int index, double element); /** Returns a mutable clone of this list with the specified capacity. */ @@ -680,6 +684,7 @@ public final class Internal { void addFloat(float element); /** Like {@link #set(int, Object)} but more efficient in that it doesn't box the element. */ + @CanIgnoreReturnValue float setFloat(int index, float element); /** Returns a mutable clone of this list with the specified capacity. */ diff --git a/java/core/src/main/java/com/google/protobuf/RepeatedFieldBuilder.java b/java/core/src/main/java/com/google/protobuf/RepeatedFieldBuilder.java index d56af6b0e1..757bc6656c 100644 --- a/java/core/src/main/java/com/google/protobuf/RepeatedFieldBuilder.java +++ b/java/core/src/main/java/com/google/protobuf/RepeatedFieldBuilder.java @@ -277,6 +277,7 @@ public class RepeatedFieldBuilder< * @param message the message to set * @return the builder */ + @CanIgnoreReturnValue public RepeatedFieldBuilder setMessage(int index, MType message) { checkNotNull(message); ensureMutableMessageList(); @@ -298,6 +299,7 @@ public class RepeatedFieldBuilder< * @param message the message to add * @return the builder */ + @CanIgnoreReturnValue public RepeatedFieldBuilder addMessage(MType message) { checkNotNull(message); ensureMutableMessageList(); @@ -319,6 +321,7 @@ public class RepeatedFieldBuilder< * @param message the message to add * @return the builder */ + @CanIgnoreReturnValue public RepeatedFieldBuilder addMessage(int index, MType message) { checkNotNull(message); ensureMutableMessageList(); @@ -338,6 +341,7 @@ public class RepeatedFieldBuilder< * @param values the messages to add * @return the builder */ + @CanIgnoreReturnValue public RepeatedFieldBuilder addAllMessages( Iterable values) { for (final MType value : values) { diff --git a/java/core/src/main/java/com/google/protobuf/RepeatedFieldBuilderV3.java b/java/core/src/main/java/com/google/protobuf/RepeatedFieldBuilderV3.java index f6acc77393..25b212373f 100644 --- a/java/core/src/main/java/com/google/protobuf/RepeatedFieldBuilderV3.java +++ b/java/core/src/main/java/com/google/protobuf/RepeatedFieldBuilderV3.java @@ -277,6 +277,7 @@ public class RepeatedFieldBuilderV3< * @param message the message to set * @return the builder */ + @CanIgnoreReturnValue public RepeatedFieldBuilderV3 setMessage(int index, MType message) { checkNotNull(message); ensureMutableMessageList(); @@ -298,6 +299,7 @@ public class RepeatedFieldBuilderV3< * @param message the message to add * @return the builder */ + @CanIgnoreReturnValue public RepeatedFieldBuilderV3 addMessage(MType message) { checkNotNull(message); ensureMutableMessageList(); @@ -319,6 +321,7 @@ public class RepeatedFieldBuilderV3< * @param message the message to add * @return the builder */ + @CanIgnoreReturnValue public RepeatedFieldBuilderV3 addMessage(int index, MType message) { checkNotNull(message); ensureMutableMessageList(); @@ -338,6 +341,7 @@ public class RepeatedFieldBuilderV3< * @param values the messages to add * @return the builder */ + @CanIgnoreReturnValue public RepeatedFieldBuilderV3 addAllMessages( Iterable values) { for (final MType value : values) { diff --git a/java/core/src/main/java/com/google/protobuf/SingleFieldBuilder.java b/java/core/src/main/java/com/google/protobuf/SingleFieldBuilder.java index acdc1de183..ca257564b6 100644 --- a/java/core/src/main/java/com/google/protobuf/SingleFieldBuilder.java +++ b/java/core/src/main/java/com/google/protobuf/SingleFieldBuilder.java @@ -156,6 +156,7 @@ public class SingleFieldBuilder< * @param message the message to set * @return the builder */ + @CanIgnoreReturnValue public SingleFieldBuilder setMessage(MType message) { this.message = checkNotNull(message); if (builder != null) { @@ -172,6 +173,7 @@ public class SingleFieldBuilder< * @param value the value to merge from * @return the builder */ + @CanIgnoreReturnValue public SingleFieldBuilder mergeFrom(MType value) { if (builder == null && message == message.getDefaultInstanceForType()) { message = value; @@ -188,6 +190,7 @@ public class SingleFieldBuilder< * @return the builder */ @SuppressWarnings("unchecked") + @CanIgnoreReturnValue public SingleFieldBuilder clear() { message = (MType) diff --git a/java/core/src/main/java/com/google/protobuf/SingleFieldBuilderV3.java b/java/core/src/main/java/com/google/protobuf/SingleFieldBuilderV3.java index 78a4a21664..c235495d62 100644 --- a/java/core/src/main/java/com/google/protobuf/SingleFieldBuilderV3.java +++ b/java/core/src/main/java/com/google/protobuf/SingleFieldBuilderV3.java @@ -156,6 +156,7 @@ public class SingleFieldBuilderV3< * @param message the message to set * @return the builder */ + @CanIgnoreReturnValue public SingleFieldBuilderV3 setMessage(MType message) { this.message = checkNotNull(message); if (builder != null) { @@ -172,6 +173,7 @@ public class SingleFieldBuilderV3< * @param value the value to merge from * @return the builder */ + @CanIgnoreReturnValue public SingleFieldBuilderV3 mergeFrom(MType value) { if (builder == null && message == message.getDefaultInstanceForType()) { message = value; @@ -188,6 +190,7 @@ public class SingleFieldBuilderV3< * @return the builder */ @SuppressWarnings("unchecked") + @CanIgnoreReturnValue public SingleFieldBuilderV3 clear() { message = (MType) diff --git a/java/core/src/test/java/com/google/protobuf/SingleFieldBuilderV3Test.java b/java/core/src/test/java/com/google/protobuf/SingleFieldBuilderV3Test.java index d2215b0d5b..872eaf4bae 100644 --- a/java/core/src/test/java/com/google/protobuf/SingleFieldBuilderV3Test.java +++ b/java/core/src/test/java/com/google/protobuf/SingleFieldBuilderV3Test.java @@ -82,7 +82,7 @@ public class SingleFieldBuilderV3Test { assertThat(mockParent.getInvalidationCount()).isEqualTo(0); assertThat(builder.getBuilder().getOptionalInt32()).isEqualTo(1); assertThat(builder.getMessage().getOptionalInt32()).isEqualTo(1); - builder.build(); + TestAllTypes unused = builder.build(); builder.getBuilder().setOptionalInt32(2); assertThat(builder.getBuilder().getOptionalInt32()).isEqualTo(2); assertThat(builder.getMessage().getOptionalInt32()).isEqualTo(2); diff --git a/java/core/src/test/java/com/google/protobuf/TestBadIdentifiers.java b/java/core/src/test/java/com/google/protobuf/TestBadIdentifiers.java index 38d2471d1f..ad512a9036 100644 --- a/java/core/src/test/java/com/google/protobuf/TestBadIdentifiers.java +++ b/java/core/src/test/java/com/google/protobuf/TestBadIdentifiers.java @@ -49,7 +49,7 @@ public class TestBadIdentifiers extends TestCase { TestBadIdentifiersProto.Override.getDefaultInstance(); } - @SuppressWarnings("IgnoredPureGetter") // TODO(b/221602772): Fix this + @SuppressWarnings({"IgnoredPureGetter", "CheckReturnValue"}) // TODO(b/221602772): Fix this public void testGetDescriptor() { TestBadIdentifiersProto.getDescriptor(); TestBadIdentifiersProto.Descriptor.getDefaultInstance().getDescriptor(); diff --git a/java/core/src/test/java/com/google/protobuf/TextFormatTest.java b/java/core/src/test/java/com/google/protobuf/TextFormatTest.java index 1689c72e97..ccb86b5ecd 100644 --- a/java/core/src/test/java/com/google/protobuf/TextFormatTest.java +++ b/java/core/src/test/java/com/google/protobuf/TextFormatTest.java @@ -823,6 +823,7 @@ public class TextFormatTest { } } + @CanIgnoreReturnValue private TestAllTypes assertParseSuccessWithOverwriteForbidden(String text) throws TextFormat.ParseException { TestAllTypes.Builder builder = TestAllTypes.newBuilder(); diff --git a/src/google/protobuf/compiler/cpp/message.cc b/src/google/protobuf/compiler/cpp/message.cc index 80cce7475f..04bb5d1492 100644 --- a/src/google/protobuf/compiler/cpp/message.cc +++ b/src/google/protobuf/compiler/cpp/message.cc @@ -3052,7 +3052,7 @@ void MessageGenerator::GenerateClear(io::Printer* printer) { GOOGLE_CHECK(!first_split_chunk_processed || chunk_is_split); if (chunk_is_split && !first_split_chunk_processed) { // Some fields are cleared without checking has_bit. So we add the - // condidtion here to avoid writing to the default split instance. + // condition here to avoid writing to the default split instance. format("if (!IsSplitMessageDefault()) {\n"); format.Indent(); first_split_chunk_processed = true; diff --git a/src/google/protobuf/util/json_format_proto3.proto b/src/google/protobuf/util/json_format_proto3.proto index 6ac7611781..f9c5199e3a 100644 --- a/src/google/protobuf/util/json_format_proto3.proto +++ b/src/google/protobuf/util/json_format_proto3.proto @@ -180,6 +180,11 @@ message TestBoolValue { map bool_map = 2; } +message TestNullValue { + google.protobuf.NullValue null_value = 20; + repeated google.protobuf.NullValue repeated_null_value = 21; +} + message TestCustomJsonName { int32 value = 1 [json_name = "@value"]; } diff --git a/src/google/protobuf/util/json_util_test.cc b/src/google/protobuf/util/json_util_test.cc index bb464e943f..1ff638b66e 100644 --- a/src/google/protobuf/util/json_util_test.cc +++ b/src/google/protobuf/util/json_util_test.cc @@ -973,6 +973,24 @@ TEST_P(JsonTest, TestFieldMask) { EXPECT_EQ(m2->value().paths(0), "yep.really"); } +TEST_P(JsonTest, TestLegalNullsInArray) { + auto m = ToProto(R"json({ + "repeatedNullValue": [null] + })json"); + ASSERT_OK(m); + + EXPECT_EQ(m->repeated_null_value_size(), 1); + EXPECT_EQ(m->repeated_null_value(0), google::protobuf::NULL_VALUE); + + auto m2 = ToProto(R"json({ + "repeatedValue": [null] + })json"); + ASSERT_OK(m2); + + EXPECT_EQ(m2->repeated_value_size(), 1); + EXPECT_TRUE(m2->repeated_value(0).has_null_value()); +} + TEST_P(JsonTest, DISABLED_HtmlEscape) { TestMessage m; m.set_string_value("");