Merge tag 'refs/tags/sync-piper' into sync-stage

pull/10817/head
Mike Kruskal 2 years ago
commit 25e7b5a3c3
  1. 3
      java/core/BUILD.bazel
  2. 2
      java/core/generate-test-sources-build.xml
  3. 7
      java/core/src/main/java/com/google/protobuf/AbstractMessage.java
  4. 1
      java/core/src/main/java/com/google/protobuf/AbstractMessageLite.java
  5. 14
      java/core/src/main/java/com/google/protobuf/CodedInputStream.java
  6. 1
      java/core/src/main/java/com/google/protobuf/Descriptors.java
  7. 1
      java/core/src/main/java/com/google/protobuf/DynamicMessage.java
  8. 1
      java/core/src/main/java/com/google/protobuf/ExtensionRegistry.java
  9. 1
      java/core/src/main/java/com/google/protobuf/ExtensionRegistryFactory.java
  10. 1
      java/core/src/main/java/com/google/protobuf/ExtensionRegistryLite.java
  11. 2
      java/core/src/main/java/com/google/protobuf/FieldSet.java
  12. 3
      java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java
  13. 8
      java/core/src/main/java/com/google/protobuf/GeneratedMessageV3.java
  14. 3
      java/core/src/main/java/com/google/protobuf/Internal.java
  15. 4
      java/core/src/main/java/com/google/protobuf/MapField.java
  16. 1
      java/core/src/main/java/com/google/protobuf/Message.java
  17. 1
      java/core/src/main/java/com/google/protobuf/MessageLite.java
  18. 1
      java/core/src/main/java/com/google/protobuf/MessageReflection.java
  19. 13
      java/core/src/main/java/com/google/protobuf/TextFormat.java
  20. 1
      java/core/src/main/java/com/google/protobuf/TypeRegistry.java
  21. 1
      java/core/src/main/java/com/google/protobuf/UnknownFieldSet.java
  22. 1
      java/core/src/main/java/com/google/protobuf/UnsafeByteOperations.java
  23. 1
      java/core/src/test/java/com/google/protobuf/AnyTest.java
  24. 2
      java/core/src/test/java/com/google/protobuf/CodedInputStreamTest.java
  25. 3
      java/core/src/test/java/com/google/protobuf/DescriptorsTest.java
  26. 1
      java/core/src/test/java/com/google/protobuf/FieldPresenceTest.java
  27. 1
      java/core/src/test/java/com/google/protobuf/GeneratedMessageTest.java
  28. 2
      java/core/src/test/java/com/google/protobuf/LazyFieldLiteTest.java
  29. 35
      java/core/src/test/java/com/google/protobuf/MapForProto2Test.java
  30. 30
      java/core/src/test/java/com/google/protobuf/MapTest.java
  31. 2
      java/core/src/test/java/com/google/protobuf/ParserTest.java
  32. 2
      java/core/src/test/java/com/google/protobuf/TestBadIdentifiers.java
  33. 112
      java/core/src/test/java/com/google/protobuf/TextFormatPerformanceTest.java
  34. 4
      java/core/src/test/java/com/google/protobuf/TextFormatTest.java
  35. 1
      java/core/src/test/java/com/google/protobuf/TypeRegistryTest.java
  36. 52
      java/core/src/test/proto/com/google/protobuf/proto2_text_format_performance_test.proto
  37. 44
      java/core/src/test/proto/com/google/protobuf/proto3_text_format_performance_test.proto
  38. 30
      java/internal/JavaVersionTest.java
  39. 1
      java/lite/pom.xml
  40. 1
      java/lite/src/test/java/com/google/protobuf/LiteTest.java
  41. 1
      java/util/src/main/java/com/google/protobuf/util/JsonFormat.java
  42. 1
      java/util/src/test/java/com/google/protobuf/util/JsonFormatTest.java
  43. 1
      java/util/src/test/java/com/google/protobuf/util/StructsTest.java
  44. 1
      python/google/protobuf/internal/descriptor_pool_test.py
  45. 3
      python/google/protobuf/internal/message_test.py
  46. 1
      python/google/protobuf/internal/reflection_test.py
  47. 2
      python/google/protobuf/internal/text_format_test.py
  48. 1
      src/google/protobuf/arena_unittest.cc
  49. 25
      src/google/protobuf/arenastring.cc
  50. 12
      src/google/protobuf/arenastring.h
  51. 2
      src/google/protobuf/compiler/cpp/field.cc
  52. 8
      src/google/protobuf/compiler/cpp/file.cc
  53. 2
      src/google/protobuf/compiler/cpp/message.cc
  54. 11
      src/google/protobuf/generated_message_tctable_gen.cc
  55. 1
      src/google/protobuf/generated_message_tctable_impl.h
  56. 2
      src/google/protobuf/generated_message_tctable_lite.cc
  57. 1
      src/google/protobuf/json/internal/untyped_message.h
  58. 14
      src/google/protobuf/map_entry_lite.h
  59. 2
      src/google/protobuf/message.h
  60. 19
      src/google/protobuf/port_def.inc
  61. 4
      src/google/protobuf/port_undef.inc
  62. 8
      src/google/protobuf/unittest.proto

@ -191,8 +191,8 @@ java_export(
maven_coordinates = "com.google.protobuf:protobuf-java:%s" % PROTOBUF_JAVA_VERSION,
pom_template = "pom_template.xml",
resources = [
"//src/google/protobuf:descriptor_proto_srcs",
"//:well_known_type_protos",
"//src/google/protobuf:descriptor_proto_srcs",
],
tags = ["manual"],
runtime_deps = [":core"],
@ -442,6 +442,7 @@ LITE_TEST_EXCLUSIONS = [
"src/test/java/com/google/protobuf/TestBadIdentifiers.java",
"src/test/java/com/google/protobuf/TextFormatParseInfoTreeTest.java",
"src/test/java/com/google/protobuf/TextFormatParseLocationTest.java",
"src/test/java/com/google/protobuf/TextFormatPerformanceTest.java",
"src/test/java/com/google/protobuf/TextFormatTest.java",
"src/test/java/com/google/protobuf/TestUtil.java",
"src/test/java/com/google/protobuf/TestUtilLite.java",

@ -43,8 +43,10 @@
<arg value="${test.proto.dir}/com/google/protobuf/proto2_message.proto"/>
<arg value="${test.proto.dir}/com/google/protobuf/proto2_message_lite.proto"/>
<arg value="${test.proto.dir}/com/google/protobuf/proto2_unknown_enum_values.proto"/>
<arg value="${test.proto.dir}/com/google/protobuf/proto2_text_format_performance_test.proto"/>
<arg value="${test.proto.dir}/com/google/protobuf/proto3_message.proto"/>
<arg value="${test.proto.dir}/com/google/protobuf/proto3_message_lite.proto"/>
<arg value="${test.proto.dir}/com/google/protobuf/proto3_text_format_performance_test.proto"/>
<arg value="${test.proto.dir}/com/google/protobuf/test_bad_identifiers.proto"/>
<arg value="${test.proto.dir}/com/google/protobuf/test_check_utf8.proto"/>
<arg value="${test.proto.dir}/com/google/protobuf/test_check_utf8_size.proto"/>

@ -83,7 +83,6 @@ public abstract class AbstractMessage
throw new UnsupportedOperationException("Nested builder is not supported for this type.");
}
@Override
public List<String> findInitializationErrors() {
return MessageReflection.findMissingFields(this);
@ -571,7 +570,7 @@ public abstract class AbstractMessage
protected static int hashLong(long n) {
return (int) (n ^ (n >>> 32));
}
//
/**
* @deprecated from v3.0.0-beta-3+, for compatibility with v2.5.0 and v2.6.1
* generated code.
@ -580,7 +579,7 @@ public abstract class AbstractMessage
protected static int hashBoolean(boolean b) {
return b ? 1231 : 1237;
}
//
/**
* @deprecated from v3.0.0-beta-3+, for compatibility with v2.5.0 and v2.6.1
* generated code.
@ -589,7 +588,7 @@ public abstract class AbstractMessage
protected static int hashEnum(EnumLite e) {
return e.getNumber();
}
//
/**
* @deprecated from v3.0.0-beta-3+, for compatibility with v2.5.0 and v2.6.1
* generated code.

@ -106,7 +106,6 @@ public abstract class AbstractMessageLite<
throw new UnsupportedOperationException();
}
int getSerializedSize(Schema schema) {
int memoizedSerializedSize = getMemoizedSerializedSize();
if (memoizedSerializedSize == -1) {

@ -254,7 +254,6 @@ public abstract class CodedInputStream {
*/
public abstract void skipMessage(CodedOutputStream output) throws IOException;
// -----------------------------------------------------------------
/** Read a {@code double} field value from the stream. */
@ -300,7 +299,6 @@ public abstract class CodedInputStream {
final ExtensionRegistryLite extensionRegistry)
throws IOException;
/** Read a {@code group} field value from the stream. */
public abstract <T extends MessageLite> T readGroup(
final int fieldNumber, final Parser<T> parser, final ExtensionRegistryLite extensionRegistry)
@ -322,7 +320,6 @@ public abstract class CodedInputStream {
final MessageLite.Builder builder, final ExtensionRegistryLite extensionRegistry)
throws IOException;
/** Read an embedded message field value from the stream. */
public abstract <T extends MessageLite> T readMessage(
final Parser<T> parser, final ExtensionRegistryLite extensionRegistry) throws IOException;
@ -745,7 +742,6 @@ public abstract class CodedInputStream {
}
}
// -----------------------------------------------------------------
@Override
@ -839,7 +835,6 @@ public abstract class CodedInputStream {
--recursionDepth;
}
@Override
public <T extends MessageLite> T readGroup(
final int fieldNumber,
@ -878,7 +873,6 @@ public abstract class CodedInputStream {
popLimit(oldLimit);
}
@Override
public <T extends MessageLite> T readMessage(
final Parser<T> parser, final ExtensionRegistryLite extensionRegistry) throws IOException {
@ -1460,7 +1454,6 @@ public abstract class CodedInputStream {
}
}
// -----------------------------------------------------------------
@Override
@ -1559,7 +1552,6 @@ public abstract class CodedInputStream {
--recursionDepth;
}
@Override
public <T extends MessageLite> T readGroup(
final int fieldNumber,
@ -1598,7 +1590,6 @@ public abstract class CodedInputStream {
popLimit(oldLimit);
}
@Override
public <T extends MessageLite> T readMessage(
final Parser<T> parser, final ExtensionRegistryLite extensionRegistry) throws IOException {
@ -2253,7 +2244,6 @@ public abstract class CodedInputStream {
}
}
// -----------------------------------------------------------------
@Override
@ -2359,7 +2349,6 @@ public abstract class CodedInputStream {
--recursionDepth;
}
@Override
public <T extends MessageLite> T readGroup(
final int fieldNumber,
@ -2398,7 +2387,6 @@ public abstract class CodedInputStream {
popLimit(oldLimit);
}
@Override
public <T extends MessageLite> T readMessage(
final Parser<T> parser, final ExtensionRegistryLite extensionRegistry) throws IOException {
@ -3454,7 +3442,6 @@ public abstract class CodedInputStream {
--recursionDepth;
}
@Override
public <T extends MessageLite> T readGroup(
final int fieldNumber,
@ -3493,7 +3480,6 @@ public abstract class CodedInputStream {
popLimit(oldLimit);
}
@Override
public <T extends MessageLite> T readMessage(
final Parser<T> parser, final ExtensionRegistryLite extensionRegistry) throws IOException {

@ -1728,7 +1728,6 @@ public final class Descriptors {
// down-cast and call mergeFrom directly.
return ((Message.Builder) to).mergeFrom((Message) from);
}
}
// =================================================================

@ -86,7 +86,6 @@ public final class DynamicMessage extends AbstractMessage {
UnknownFieldSet.getDefaultInstance());
}
/** Parse a message of the given type from the given input stream. */
public static DynamicMessage parseFrom(Descriptor type, CodedInputStream input)
throws IOException {

@ -99,7 +99,6 @@ public class ExtensionRegistry extends ExtensionRegistryLite {
return EMPTY_REGISTRY;
}
/** Returns an unmodifiable view of the registry. */
@Override
public ExtensionRegistry getUnmodifiable() {

@ -70,7 +70,6 @@ final class ExtensionRegistryFactory {
return result != null ? result : EMPTY_REGISTRY_LITE;
}
static boolean isFullRegistry(ExtensionRegistryLite registry) {
return EXTENSION_REGISTRY_CLASS != null
&& EXTENSION_REGISTRY_CLASS.isAssignableFrom(registry.getClass());

@ -138,7 +138,6 @@ public class ExtensionRegistryLite {
return result;
}
/** Returns an unmodifiable view of the registry. */
public ExtensionRegistryLite getUnmodifiable() {
return new ExtensionRegistryLite(this);

@ -185,7 +185,6 @@ final class FieldSet<T extends FieldSet.FieldDescriptorLite<T>> {
return clone;
}
// =================================================================
/** See {@link Message.Builder#clear()}. */
@ -574,7 +573,6 @@ final class FieldSet<T extends FieldSet.FieldDescriptorLite<T>> {
}
}
/** See {@link Message#writeTo(CodedOutputStream)}. */
public void writeTo(final CodedOutputStream output) throws IOException {
for (int i = 0; i < fields.getNumArrayEntries(); i++) {

@ -586,7 +586,6 @@ public abstract class GeneratedMessageLite<
}
}
// =================================================================
// Extensions-related stuff
@ -1250,7 +1249,6 @@ public abstract class GeneratedMessageLite<
return ((Builder) to).mergeFrom((GeneratedMessageLite) from);
}
@Override
public int compareTo(ExtensionDescriptor other) {
return number - other.number;
@ -1291,7 +1289,6 @@ public abstract class GeneratedMessageLite<
}
}
/**
* Lite equivalent to {@link GeneratedMessage.GeneratedExtension}.
*

@ -456,7 +456,6 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri
size == 0 ? AbstractProtobufList.DEFAULT_CAPACITY : size * 2);
}
@Override
public void writeTo(final CodedOutputStream output) throws IOException {
MessageReflection.writeMessageTo(this, getAllFieldsRaw(), output, false);
@ -474,7 +473,6 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri
return memoizedSize;
}
/**
* This class is used to make a generated protected method inaccessible from user's code (e.g.,
* the {@link #newInstance} method below). When this class is used as a parameter's type in a
@ -520,6 +518,7 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri
});
}
/** Builder class for {@link GeneratedMessageV3}. */
@SuppressWarnings("unchecked")
public abstract static class Builder<BuilderType extends Builder<BuilderType>>
extends AbstractMessage.Builder<BuilderType> {
@ -879,7 +878,7 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri
}
/**
* Called when a the builder or one of its nested children has changed and any parent should be
* Called when a builder or one of its nested children has changed and any parent should be
* notified of its invalidation.
*/
protected final void onChanged() {
@ -919,6 +918,7 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri
// =================================================================
// Extensions-related stuff
/** Extends {@link MessageOrBuilder} with extension-related functions. */
public interface ExtendableMessageOrBuilder<MessageType extends ExtendableMessage>
extends MessageOrBuilder {
// Re-define for return type covariance.
@ -1169,7 +1169,6 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri
return parseUnknownField(input, unknownFields, extensionRegistry, tag);
}
/** Used by parsing constructors in generated classes. */
@Override
protected void makeExtensionsImmutable() {
@ -1847,7 +1846,6 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri
FieldDescriptor getDescriptor();
}
// =================================================================
/** Calls Class.getMethod and throws a RuntimeException if it fails. */

@ -375,7 +375,6 @@ public final class Internal {
}
}
/** An empty byte array constant used in generated code. */
public static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
@ -386,7 +385,6 @@ public final class Internal {
public static final CodedInputStream EMPTY_CODED_INPUT_STREAM =
CodedInputStream.newInstance(EMPTY_BYTE_ARRAY);
/** Helper method to merge two MessageLite instances. */
static Object mergeMessage(Object destination, Object source) {
return ((MessageLite) destination).toBuilder().mergeFrom((MessageLite) source).buildPartial();
@ -691,5 +689,4 @@ public final class Internal {
@Override
FloatList mutableCopyWithCapacity(int capacity);
}
}

@ -122,7 +122,6 @@ public class MapField<K, V> implements MutabilityOracle {
}
}
private final Converter<K, V> converter;
private MapField(Converter<K, V> converter, StorageMode mode, Map<K, V> mapData) {
@ -137,19 +136,16 @@ public class MapField<K, V> implements MutabilityOracle {
this(new ImmutableMessageConverter<K, V>(defaultEntry), mode, mapData);
}
/** Returns an immutable empty MapField. */
public static <K, V> MapField<K, V> emptyMapField(MapEntry<K, V> defaultEntry) {
return new MapField<K, V>(defaultEntry, StorageMode.MAP, Collections.<K, V>emptyMap());
}
/** Creates a new mutable empty MapField. */
public static <K, V> MapField<K, V> newMapField(MapEntry<K, V> defaultEntry) {
return new MapField<K, V>(defaultEntry, StorageMode.MAP, new LinkedHashMap<K, V>());
}
private Message convertKeyAndValueToMessage(K key, V value) {
return converter.convertKeyAndValueToMessage(key, value);
}

@ -51,7 +51,6 @@ public interface Message extends MessageLite, MessageOrBuilder {
@Override
Parser<? extends Message> getParserForType();
// -----------------------------------------------------------------
// Comparison and hashing

@ -123,7 +123,6 @@ public interface MessageLite extends MessageLiteOrBuilder {
*/
void writeDelimitedTo(OutputStream output) throws IOException;
// =================================================================
// Builders

@ -673,7 +673,6 @@ class MessageReflection {
}
}
static class ExtensionAdapter implements MergeTarget {
private final FieldSet<Descriptors.FieldDescriptor> extensions;

@ -132,7 +132,7 @@ public final class TextFormat {
public static String shortDebugString(final FieldDescriptor field, final Object value) {
return printer().shortDebugString(field, value);
}
//
/**
* Generates a human readable form of the unknown fields, useful for debugging and other
* purposes, with no newline characters.
@ -191,7 +191,7 @@ public final class TextFormat {
public static String printToUnicodeString(final UnknownFieldSet fields) {
return printer().escapingNonAscii(false).printToString(fields);
}
//
/** @deprecated Use {@code printer().printField(FieldDescriptor, Object, Appendable)} */
@Deprecated
public static void printField(
@ -199,13 +199,13 @@ public final class TextFormat {
throws IOException {
printer().printField(field, value, output);
}
//
/** @deprecated Use {@code printer().printFieldToString(FieldDescriptor, Object)} */
@Deprecated
public static String printFieldToString(final FieldDescriptor field, final Object value) {
return printer().printFieldToString(field, value);
}
//
/**
* Outputs a unicode textual representation of the value of given field value.
*
@ -465,7 +465,6 @@ public final class TextFormat {
@SuppressWarnings({"rawtypes"})
private MapEntry mapEntry;
private final FieldDescriptor.JavaType fieldType;
MapEntryAdapter(Object entry, FieldDescriptor fieldDescriptor) {
@ -1499,7 +1498,6 @@ public final class TextFormat {
PARSER.merge(input, extensionRegistry, builder);
}
/**
* Parse a text-format message from {@code input} and merge the contents into {@code builder}.
* Extensions will be recognized if they are registered in {@code extensionRegistry}.
@ -1530,7 +1528,6 @@ public final class TextFormat {
return output;
}
/**
* Parser for text-format proto2 instances. This class is thread-safe. The implementation largely
* follows google/protobuf/text_format.cc.
@ -1700,7 +1697,6 @@ public final class TextFormat {
merge(toStringBuilder(input), extensionRegistry, builder);
}
private static final int BUFFER_SIZE = 4096;
// TODO(chrisn): See if working around java.io.Reader#read(CharBuffer)
@ -1791,7 +1787,6 @@ public final class TextFormat {
checkUnknownFields(unknownFields);
}
/** Parse a single field from {@code tokenizer} and merge it into {@code builder}. */
private void mergeField(
final Tokenizer tokenizer,

@ -55,7 +55,6 @@ public class TypeRegistry {
return EmptyTypeRegistryHolder.EMPTY;
}
public static Builder newBuilder() {
return new Builder();
}

@ -89,7 +89,6 @@ public final class UnknownFieldSet implements MessageLite {
private static final UnknownFieldSet defaultInstance =
new UnknownFieldSet(new TreeMap<Integer, Field>());
@Override
public boolean equals(Object other) {
if (this == other) {

@ -117,5 +117,4 @@ public final class UnsafeByteOperations {
public static void unsafeWriteTo(ByteString bytes, ByteOutput output) throws IOException {
bytes.writeTo(output);
}
}

@ -58,7 +58,6 @@ public class AnyTest {
TestAllTypes result = container.getValue().unpack(TestAllTypes.class);
TestUtil.assertAllFieldsSet(result);
// Unpacking to a wrong type will throw an exception.
try {
container.getValue().unpack(TestAny.class);

@ -424,7 +424,6 @@ public class CodedInputStreamTest {
}
}
/**
* Test that a bug in skipRawBytes() has been fixed: if the skip skips exactly up to a limit, this
* should not break things.
@ -672,7 +671,6 @@ public class CodedInputStreamTest {
// success.
}
CodedInputStream input = inputType.newDecoder(data100);
input.setRecursionLimit(8);
try {

@ -324,7 +324,6 @@ public class DescriptorsTest {
assertThat(service.getFullName()).isEqualTo("protobuf_unittest.TestService");
assertThat(service.getFile()).isEqualTo(UnittestProto.getDescriptor());
MethodDescriptor fooMethod = service.getMethods().get(0);
assertThat(fooMethod.getName()).isEqualTo("Foo");
assertThat(fooMethod.getInputType()).isEqualTo(UnittestProto.FooRequest.getDescriptor());
@ -337,7 +336,6 @@ public class DescriptorsTest {
assertThat(barMethod.getOutputType()).isEqualTo(UnittestProto.BarResponse.getDescriptor());
assertThat(service.findMethodByName("Bar")).isEqualTo(barMethod);
assertThat(service.findMethodByName("NoSuchMethod")).isNull();
for (int i = 0; i < service.getMethods().size(); i++) {
@ -345,7 +343,6 @@ public class DescriptorsTest {
}
}
@Test
public void testCustomOptions() throws Exception {
// Get the descriptor indirectly from a dependent proto class. This is to

@ -500,5 +500,4 @@ public class FieldPresenceTest {
assertThat(builder.isInitialized()).isTrue();
assertThat(builder.buildPartial().isInitialized()).isTrue();
}
}

@ -801,7 +801,6 @@ public class GeneratedMessageTest {
assertThat(fieldBuilder.build().getField(field)).isEqualTo(expected);
}
@Test
public void testGetBuilderForNonMessageExtensionField() {
TestAllExtensions.Builder builder = TestAllExtensions.newBuilder();

@ -238,7 +238,6 @@ public class LazyFieldLiteTest {
.isEqualTo(messageWithExtensions);
}
// Help methods.
private LazyFieldLite createLazyFieldLiteFromMessage(MessageLite message) {
@ -262,5 +261,4 @@ public class LazyFieldLiteTest {
assertThat(unexpected).isNotSameInstanceAs(actual);
assertThat((unexpected != null && unexpected.equals(actual))).isFalse();
}
}

@ -67,26 +67,26 @@ public class MapForProto2Test {
builder.getMutableInt32ToInt32Field().put(1, 11);
builder.getMutableInt32ToInt32Field().put(2, 22);
builder.getMutableInt32ToInt32Field().put(3, 33);
//
builder.getMutableInt32ToStringField().put(1, "11");
builder.getMutableInt32ToStringField().put(2, "22");
builder.getMutableInt32ToStringField().put(3, "33");
//
builder.getMutableInt32ToBytesField().put(1, TestUtil.toBytes("11"));
builder.getMutableInt32ToBytesField().put(2, TestUtil.toBytes("22"));
builder.getMutableInt32ToBytesField().put(3, TestUtil.toBytes("33"));
//
builder.getMutableInt32ToEnumField().put(1, TestMap.EnumValue.FOO);
builder.getMutableInt32ToEnumField().put(2, TestMap.EnumValue.BAR);
builder.getMutableInt32ToEnumField().put(3, TestMap.EnumValue.BAZ);
//
builder.getMutableInt32ToMessageField().put(
1, MessageValue.newBuilder().setValue(11).build());
builder.getMutableInt32ToMessageField().put(
2, MessageValue.newBuilder().setValue(22).build());
builder.getMutableInt32ToMessageField().put(
3, MessageValue.newBuilder().setValue(33).build());
//
builder.getMutableStringToInt32Field().put("1", 11);
builder.getMutableStringToInt32Field().put("2", 22);
builder.getMutableStringToInt32Field().put("3", 33);
@ -175,25 +175,25 @@ public class MapForProto2Test {
builder.getMutableInt32ToInt32Field().put(1, 111);
builder.getMutableInt32ToInt32Field().remove(2);
builder.getMutableInt32ToInt32Field().put(4, 44);
//
builder.getMutableInt32ToStringField().put(1, "111");
builder.getMutableInt32ToStringField().remove(2);
builder.getMutableInt32ToStringField().put(4, "44");
//
builder.getMutableInt32ToBytesField().put(1, TestUtil.toBytes("111"));
builder.getMutableInt32ToBytesField().remove(2);
builder.getMutableInt32ToBytesField().put(4, TestUtil.toBytes("44"));
//
builder.getMutableInt32ToEnumField().put(1, TestMap.EnumValue.BAR);
builder.getMutableInt32ToEnumField().remove(2);
builder.getMutableInt32ToEnumField().put(4, TestMap.EnumValue.QUX);
//
builder.getMutableInt32ToMessageField().put(
1, MessageValue.newBuilder().setValue(111).build());
builder.getMutableInt32ToMessageField().remove(2);
builder.getMutableInt32ToMessageField().put(
4, MessageValue.newBuilder().setValue(44).build());
//
builder.getMutableStringToInt32Field().put("1", 111);
builder.getMutableStringToInt32Field().remove("2");
builder.getMutableStringToInt32Field().put("4", 44);
@ -234,7 +234,7 @@ public class MapForProto2Test {
assertMapValuesSet(usingAccessors);
assertThat(usingAccessors).isEqualTo(usingMutableMap);
//
usingMutableMapBuilder = usingMutableMap.toBuilder();
updateMapValuesUsingMutableMap(usingMutableMapBuilder);
usingMutableMap = usingMutableMapBuilder.build();
@ -340,7 +340,7 @@ public class MapForProto2Test {
assertThat(builder.getInt32ToInt32Field()).isEqualTo(newMap(1, 2));
builder.getMutableInt32ToInt32Field().put(2, 3);
assertThat(builder.getInt32ToInt32Field()).isEqualTo(newMap(1, 2, 2, 3));
//
Map<Integer, TestMap.EnumValue> enumMap = builder.getMutableInt32ToEnumField();
enumMap.put(1, TestMap.EnumValue.BAR);
assertThat(builder.build().getInt32ToEnumField())
@ -355,7 +355,7 @@ public class MapForProto2Test {
builder.getMutableInt32ToEnumField().put(2, TestMap.EnumValue.FOO);
assertThat(builder.getInt32ToEnumField())
.isEqualTo(newMap(1, TestMap.EnumValue.BAR, 2, TestMap.EnumValue.FOO));
//
Map<Integer, String> stringMap = builder.getMutableInt32ToStringField();
stringMap.put(1, "1");
assertThat(builder.build().getInt32ToStringField()).isEqualTo(newMap(1, "1"));
@ -368,7 +368,7 @@ public class MapForProto2Test {
assertThat(builder.getInt32ToStringField()).isEqualTo(newMap(1, "1"));
builder.getMutableInt32ToStringField().put(2, "2");
assertThat(builder.getInt32ToStringField()).isEqualTo(newMap(1, "1", 2, "2"));
//
Map<Integer, TestMap.MessageValue> messageMap = builder.getMutableInt32ToMessageField();
messageMap.put(1, TestMap.MessageValue.getDefaultInstance());
assertThat(builder.build().getInt32ToMessageField())
@ -386,7 +386,7 @@ public class MapForProto2Test {
newMap(1, TestMap.MessageValue.getDefaultInstance(),
2, TestMap.MessageValue.getDefaultInstance()));
}
//
@Test
public void testMutableMapLifecycle_collections() {
TestMap.Builder builder = TestMap.newBuilder();
@ -433,13 +433,13 @@ public class MapForProto2Test {
assertThat(builder.getInt32ToInt32Field()).isEqualTo(newMap(1, 2));
assertThat(builder.build().getInt32ToInt32Field()).isEqualTo(newMap(1, 2));
}
//
private static <K, V> Map<K, V> newMap(K key1, V value1) {
Map<K, V> map = new HashMap<K, V>();
map.put(key1, value1);
return map;
}
//
private static <K, V> Map<K, V> newMap(K key1, V value1, K key2, V value2) {
Map<K, V> map = new HashMap<K, V>();
map.put(key1, value1);
@ -635,7 +635,6 @@ public class MapForProto2Test {
// to be different.
}
// The following methods are used to test reflection API.
private static FieldDescriptor f(String name) {

@ -66,26 +66,26 @@ public class MapTest {
builder.getMutableInt32ToInt32Field().put(1, 11);
builder.getMutableInt32ToInt32Field().put(2, 22);
builder.getMutableInt32ToInt32Field().put(3, 33);
//
builder.getMutableInt32ToStringField().put(1, "11");
builder.getMutableInt32ToStringField().put(2, "22");
builder.getMutableInt32ToStringField().put(3, "33");
//
builder.getMutableInt32ToBytesField().put(1, TestUtil.toBytes("11"));
builder.getMutableInt32ToBytesField().put(2, TestUtil.toBytes("22"));
builder.getMutableInt32ToBytesField().put(3, TestUtil.toBytes("33"));
//
builder.getMutableInt32ToEnumField().put(1, TestMap.EnumValue.FOO);
builder.getMutableInt32ToEnumField().put(2, TestMap.EnumValue.BAR);
builder.getMutableInt32ToEnumField().put(3, TestMap.EnumValue.BAZ);
//
builder.getMutableInt32ToMessageField().put(
1, MessageValue.newBuilder().setValue(11).build());
builder.getMutableInt32ToMessageField().put(
2, MessageValue.newBuilder().setValue(22).build());
builder.getMutableInt32ToMessageField().put(
3, MessageValue.newBuilder().setValue(33).build());
//
builder.getMutableStringToInt32Field().put("1", 11);
builder.getMutableStringToInt32Field().put("2", 22);
builder.getMutableStringToInt32Field().put("3", 33);
@ -174,25 +174,25 @@ public class MapTest {
builder.getMutableInt32ToInt32Field().put(1, 111);
builder.getMutableInt32ToInt32Field().remove(2);
builder.getMutableInt32ToInt32Field().put(4, 44);
//
builder.getMutableInt32ToStringField().put(1, "111");
builder.getMutableInt32ToStringField().remove(2);
builder.getMutableInt32ToStringField().put(4, "44");
//
builder.getMutableInt32ToBytesField().put(1, TestUtil.toBytes("111"));
builder.getMutableInt32ToBytesField().remove(2);
builder.getMutableInt32ToBytesField().put(4, TestUtil.toBytes("44"));
//
builder.getMutableInt32ToEnumField().put(1, TestMap.EnumValue.BAR);
builder.getMutableInt32ToEnumField().remove(2);
builder.getMutableInt32ToEnumField().put(4, TestMap.EnumValue.QUX);
//
builder.getMutableInt32ToMessageField().put(
1, MessageValue.newBuilder().setValue(111).build());
builder.getMutableInt32ToMessageField().remove(2);
builder.getMutableInt32ToMessageField().put(
4, MessageValue.newBuilder().setValue(44).build());
//
builder.getMutableStringToInt32Field().put("1", 111);
builder.getMutableStringToInt32Field().remove("2");
builder.getMutableStringToInt32Field().put("4", 44);
@ -233,7 +233,7 @@ public class MapTest {
assertMapValuesSet(usingAccessors);
assertThat(usingAccessors).isEqualTo(usingMutableMap);
//
usingMutableMapBuilder = usingMutableMap.toBuilder();
updateMapValuesUsingMutableMap(usingMutableMapBuilder);
usingMutableMap = usingMutableMapBuilder.build();
@ -339,7 +339,7 @@ public class MapTest {
assertThat(builder.getInt32ToInt32Field()).isEqualTo(newMap(1, 2));
builder.getMutableInt32ToInt32Field().put(2, 3);
assertThat(builder.getInt32ToInt32Field()).isEqualTo(newMap(1, 2, 2, 3));
//
Map<Integer, TestMap.EnumValue> enumMap = builder.getMutableInt32ToEnumField();
enumMap.put(1, TestMap.EnumValue.BAR);
assertThat(builder.build().getInt32ToEnumField())
@ -354,7 +354,7 @@ public class MapTest {
builder.getMutableInt32ToEnumField().put(2, TestMap.EnumValue.FOO);
assertThat(builder.getInt32ToEnumField()).isEqualTo(
newMap(1, TestMap.EnumValue.BAR, 2, TestMap.EnumValue.FOO));
//
Map<Integer, String> stringMap = builder.getMutableInt32ToStringField();
stringMap.put(1, "1");
assertThat(builder.build().getInt32ToStringField()).isEqualTo(newMap(1, "1"));
@ -367,7 +367,7 @@ public class MapTest {
assertThat(builder.getInt32ToStringField()).isEqualTo(newMap(1, "1"));
builder.putInt32ToStringField(2, "2");
assertThat(builder.getInt32ToStringField()).isEqualTo(newMap(1, "1", 2, "2"));
//
Map<Integer, TestMap.MessageValue> messageMap = builder.getMutableInt32ToMessageField();
messageMap.put(1, TestMap.MessageValue.getDefaultInstance());
assertThat( builder.build().getInt32ToMessageField())
@ -385,7 +385,7 @@ public class MapTest {
newMap(1, TestMap.MessageValue.getDefaultInstance(),
2, TestMap.MessageValue.getDefaultInstance()));
}
//
@Test
public void testMutableMapLifecycle_collections() {
TestMap.Builder builder = TestMap.newBuilder();

@ -117,7 +117,6 @@ public class ParserTest {
assertRoundTripEquals(TestUtil.getAllSet());
}
@Test
public void testParsePartial() throws Exception {
assertParsePartial(TestRequired.parser(), TestRequired.newBuilder().setA(1).buildPartial());
@ -199,7 +198,6 @@ public class ParserTest {
assertThat(emptyMessage.toByteString()).isEqualTo(TestUtil.getAllSet().toByteString());
}
@Test
public void testOptimizeForSize() throws Exception {
TestOptimizedForSize.Builder builder = TestOptimizedForSize.newBuilder();

@ -99,7 +99,6 @@ public class TestBadIdentifiers extends TestCase {
assertEquals("", message.getFieldName33());
assertEquals(0, message.get2Conflict34());
assertEquals(0, message.get2Conflict35());
}
public void testNumberFields() throws Exception {
@ -120,6 +119,5 @@ public class TestBadIdentifiers extends TestCase {
assertEquals(0, message.get32());
assertEquals(0, message.get64Count());
assertEquals(0, message.get64List().size());
}
}

@ -0,0 +1,112 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package com.google.protobuf;
import static com.google.common.truth.Truth.assertThat;
import com.google.protobuf.testing.textformat.performance.proto2.Proto2TextFormatPerformanceProto;
import com.google.protobuf.testing.textformat.performance.proto3.Proto3TextFormatPerformanceProto;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
public class TextFormatPerformanceTest {
// 10 Seconds is longer than we'd really like, but necesssary to keep this test from being flaky.
// This test is mostly to make sure it doesn't explode to many 10s of seconds for some reason.
private static final long MAX_PARSE_TIME_MS = 10_000L;
private static final int REPEAT_COUNT = 400000;
private static final String CONTAINS_SUB_MESSAGE_WITH_REPEATED_INT32 =
repeat("sub_msg { value: 123 }", REPEAT_COUNT);
private static final String CONTAINS_EXTENSION_SUB_MESSAGE_WITH_REPEATED_INT32 =
repeat(
"[protobuf.testing.textformat.performance.proto2.sub_msg_ext] { value: 123 }",
REPEAT_COUNT);
// OSS Tests are still using JDK 8, which doesn't have JDK 11 String.repeat()
private static String repeat(String text, int count) {
StringBuilder builder = new StringBuilder(text.length() * count);
for (int i = 0; i < count; ++i) {
builder.append(text);
}
return builder.toString();
}
@Test(timeout = MAX_PARSE_TIME_MS)
public void testProto2ImmutableTextFormatParsing() throws Exception {
Proto2TextFormatPerformanceProto.ContainsSubMessageWithRepeatedInt32.Builder builder =
Proto2TextFormatPerformanceProto.ContainsSubMessageWithRepeatedInt32.newBuilder();
TextFormat.merge(CONTAINS_SUB_MESSAGE_WITH_REPEATED_INT32, builder);
Proto2TextFormatPerformanceProto.ContainsSubMessageWithRepeatedInt32 msg = builder.build();
assertThat(msg.getSubMsg().getValueCount()).isEqualTo(REPEAT_COUNT);
for (int i = 0; i < msg.getSubMsg().getValueCount(); ++i) {
assertThat(msg.getSubMsg().getValue(i)).isEqualTo(123);
}
}
@Test(timeout = MAX_PARSE_TIME_MS)
public void testProto2ImmutableExtensionTextFormatParsing() throws Exception {
ExtensionRegistry registry = ExtensionRegistry.newInstance();
Proto2TextFormatPerformanceProto.registerAllExtensions(registry);
Proto2TextFormatPerformanceProto.ContainsExtensionSubMessage.Builder builder =
Proto2TextFormatPerformanceProto.ContainsExtensionSubMessage.newBuilder();
TextFormat.merge(CONTAINS_EXTENSION_SUB_MESSAGE_WITH_REPEATED_INT32, registry, builder);
Proto2TextFormatPerformanceProto.ContainsExtensionSubMessage msg = builder.build();
assertThat(msg.getExtension(Proto2TextFormatPerformanceProto.subMsgExt).getValueCount())
.isEqualTo(REPEAT_COUNT);
for (int i = 0;
i < msg.getExtension(Proto2TextFormatPerformanceProto.subMsgExt).getValueCount();
++i) {
assertThat(msg.getExtension(Proto2TextFormatPerformanceProto.subMsgExt).getValue(i))
.isEqualTo(123);
}
}
@Test(timeout = MAX_PARSE_TIME_MS)
public void testProto3ImmutableTextFormatParsing() throws Exception {
Proto3TextFormatPerformanceProto.ContainsSubMessageWithRepeatedInt32.Builder builder =
Proto3TextFormatPerformanceProto.ContainsSubMessageWithRepeatedInt32.newBuilder();
TextFormat.merge(CONTAINS_SUB_MESSAGE_WITH_REPEATED_INT32, builder);
Proto3TextFormatPerformanceProto.ContainsSubMessageWithRepeatedInt32 msg = builder.build();
assertThat(msg.getSubMsg().getValueCount()).isEqualTo(REPEAT_COUNT);
for (int i = 0; i < msg.getSubMsg().getValueCount(); ++i) {
assertThat(msg.getSubMsg().getValue(i)).isEqualTo(123);
}
}
}

@ -724,7 +724,6 @@ public class TextFormatTest {
assertThat(actual).isEqualTo(expected);
}
@Test
public void testMergeAny_customBuiltTypeRegistry() throws Exception {
TestAny.Builder builder = TestAny.newBuilder();
@ -759,7 +758,6 @@ public class TextFormatTest {
.build());
}
private void assertParseError(String error, String text) {
// Test merge().
TestAllTypes.Builder builder = TestAllTypes.newBuilder();
@ -1399,7 +1397,6 @@ public class TextFormatTest {
.isEqualTo("1: \"\\343\\201\\202\"\n");
}
@Test
public void testParseUnknownExtensions() throws Exception {
TestUtil.TestLogHandler logHandler = new TestUtil.TestLogHandler();
@ -1844,5 +1841,4 @@ public class TextFormatTest {
assertThat(TextFormat.printer().printToString(message))
.isEqualTo("optional_float: -0.0\noptional_double: -0.0\n");
}
}

@ -65,5 +65,4 @@ public final class TypeRegistryTest {
.getDescriptorForTypeUrl("type.googleapis.com/" + descriptor.getFullName()))
.isSameInstanceAs(descriptor);
}
}

@ -0,0 +1,52 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
syntax = "proto2";
package protobuf.testing.textformat.performance.proto2;
option java_package = "com.google.protobuf.testing.textformat.performance.proto2";
option java_outer_classname = "Proto2TextFormatPerformanceProto";
message ContainsSubMessageWithRepeatedInt32 {
optional RepeatedInt32 sub_msg = 1;
}
message RepeatedInt32 {
repeated int32 value = 2;
}
message ContainsExtensionSubMessage {
extensions 1 to max;
}
extend ContainsExtensionSubMessage {
optional RepeatedInt32 sub_msg_ext = 1;
}

@ -0,0 +1,44 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
syntax = "proto3";
package protobuf.testing.textformat.performance.proto3;
option java_package = "com.google.protobuf.testing.textformat.performance.proto3";
option java_outer_classname = "Proto3TextFormatPerformanceProto";
message ContainsSubMessageWithRepeatedInt32 {
optional RepeatedInt32 sub_msg = 1;
}
message RepeatedInt32 {
repeated int32 value = 2;
}

@ -1,3 +1,33 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Test that Kokoro is using the expected version of Java.
import static com.google.common.truth.Truth.assertWithMessage;

@ -229,6 +229,7 @@
<exclude>TestBadIdentifiers.java</exclude>
<exclude>TextFormatParseInfoTreeTest.java</exclude>
<exclude>TextFormatParseLocationTest.java</exclude>
<exclude>TextFormatPerformanceTest.java</exclude>
<exclude>TextFormatTest.java</exclude>
<exclude>TestUtil.java</exclude>
<exclude>TypeRegistryTest.java</exclude>

@ -1526,7 +1526,6 @@ public class LiteTest {
assertToStringEquals("optional_double: 3.14\noptional_float: 2.72", proto);
}
@Test
public void testToStringStringFields() throws Exception {
TestAllTypesLite proto =

@ -534,7 +534,6 @@ public class JsonFormat {
this.types = types;
}
/** A Builder is used to build {@link TypeRegistry}. */
public static class Builder {
private Builder() {}

@ -1019,7 +1019,6 @@ public class JsonFormatTest {
assertRoundTripEquals(message);
}
@Test
public void testAnyFieldsWithCustomAddedTypeRegistry() throws Exception {
TestAllTypes content = TestAllTypes.newBuilder().setOptionalInt32(1234).build();

@ -61,5 +61,4 @@ public final class StructsTest {
assertThat(Structs.of("k1", Values.of(1), "k2", Values.of(2), "k3", Values.of(3)))
.isEqualTo(expected.build());
}
}

@ -56,7 +56,6 @@ from google.protobuf import message_factory
from google.protobuf import symbol_database
warnings.simplefilter('error', DeprecationWarning)

@ -1530,7 +1530,6 @@ class Proto2Test(unittest.TestCase):
self.assertEqual(100, msg.optional_int32)
self.assertEqual(200, msg.optional_fixed32)
def test_documentation(self):
# Also used by the interactive help() function.
doc = pydoc.html.document(unittest_pb2.TestAllTypes, 'message')
@ -2490,8 +2489,6 @@ class Proto3Test(unittest.TestCase):
unittest_proto3_arena_pb2.TestAllTypes().optional_nested_message)
@testing_refleaks.TestCase
class ValidTypeNamesTest(unittest.TestCase):

@ -3220,7 +3220,6 @@ class OptionsTest(unittest.TestCase):
field_descriptor.label)
@testing_refleaks.TestCase
class ClassAPITest(unittest.TestCase):

@ -2483,7 +2483,5 @@ class OptionalColonMessageToStringTest(unittest.TestCase):
message, use_short_repeated_primitives=True, force_colon=True)
self.assertEqual('repeated_int32: [1]\n', output)
if __name__ == '__main__':
unittest.main()

@ -70,6 +70,7 @@ using protobuf_unittest::TestAllExtensions;
using protobuf_unittest::TestAllTypes;
using protobuf_unittest::TestEmptyMessage;
using protobuf_unittest::TestOneof2;
using protobuf_unittest::TestRepeatedString;
namespace google {
namespace protobuf {

@ -140,6 +140,31 @@ void ArenaStringPtr::Set(absl::string_view value, Arena* arena) {
}
}
template <>
void ArenaStringPtr::Set(const std::string& value, Arena* arena) {
ScopedCheckPtrInvariants check(&tagged_ptr_);
if (IsDefault()) {
// If we're not on an arena, skip straight to a true string to avoid
// possible copy cost later.
tagged_ptr_ = arena != nullptr ? CreateArenaString(*arena, value)
: CreateString(value);
} else {
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (arena == nullptr) {
auto* old = tagged_ptr_.GetIfAllocated();
tagged_ptr_ = CreateString(value);
delete old;
} else {
auto* old = UnsafeMutablePointer();
tagged_ptr_ = CreateArenaString(*arena, value);
old->assign("garbagedata");
}
#else // PROTOBUF_FORCE_COPY_DEFAULT_STRING
UnsafeMutablePointer()->assign(value);
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
}
}
void ArenaStringPtr::Set(std::string&& value, Arena* arena) {
ScopedCheckPtrInvariants check(&tagged_ptr_);
if (IsDefault()) {

@ -262,11 +262,15 @@ struct PROTOBUF_EXPORT ArenaStringPtr {
void Set(absl::string_view value, Arena* arena);
void Set(std::string&& value, Arena* arena);
template <typename... OverloadDisambiguator>
void Set(const std::string& value, Arena* arena);
void Set(const char* s, Arena* arena);
void Set(const char* s, size_t n, Arena* arena);
void SetBytes(absl::string_view value, Arena* arena);
void SetBytes(std::string&& value, Arena* arena);
template <typename... OverloadDisambiguator>
void SetBytes(const std::string& value, Arena* arena);
void SetBytes(const char* s, Arena* arena);
void SetBytes(const void* p, size_t n, Arena* arena);
@ -418,6 +422,14 @@ inline void ArenaStringPtr::SetBytes(absl::string_view value, Arena* arena) {
Set(value, arena);
}
template <>
void ArenaStringPtr::Set(const std::string& value, Arena* arena);
template <>
inline void ArenaStringPtr::SetBytes(const std::string& value, Arena* arena) {
Set(value, arena);
}
inline void ArenaStringPtr::SetBytes(std::string&& value, Arena* arena) {
Set(std::move(value), arena);
}

@ -301,7 +301,7 @@ void SetCommonOneofFieldVariables(
}
void FieldGenerator::SetHasBitIndex(int32_t has_bit_index) {
if (!internal::cpp::HasHasbit(descriptor_)) {
if (!internal::cpp::HasHasbit(descriptor_) || has_bit_index < 0) {
GOOGLE_CHECK_EQ(has_bit_index, -1);
return;
}

@ -112,7 +112,7 @@ FileGenerator::FileGenerator(const FileDescriptor* file, const Options& options)
std::vector<const Descriptor*> msgs = FlattenMessagesInFile(file);
for (int i = 0; i < msgs.size(); ++i) {
message_generators_.push_back(absl::make_unique<MessageGenerator>(
message_generators_.push_back(std::make_unique<MessageGenerator>(
msgs[i], variables_, i, options, &scc_analyzer_));
message_generators_.back()->AddGenerators(&enum_generators_,
&extension_generators_);
@ -120,11 +120,11 @@ FileGenerator::FileGenerator(const FileDescriptor* file, const Options& options)
for (int i = 0; i < file->enum_type_count(); ++i) {
enum_generators_.push_back(
absl::make_unique<EnumGenerator>(file->enum_type(i), options));
std::make_unique<EnumGenerator>(file->enum_type(i), options));
}
for (int i = 0; i < file->service_count(); ++i) {
service_generators_.push_back(absl::make_unique<ServiceGenerator>(
service_generators_.push_back(std::make_unique<ServiceGenerator>(
file->service(i), variables_, options));
}
if (HasGenericServices(file_, options_)) {
@ -134,7 +134,7 @@ FileGenerator::FileGenerator(const FileDescriptor* file, const Options& options)
}
for (int i = 0; i < file->extension_count(); ++i) {
extension_generators_.push_back(absl::make_unique<ExtensionGenerator>(
extension_generators_.push_back(std::make_unique<ExtensionGenerator>(
file->extension(i), options, &scc_analyzer_));
}

@ -1296,7 +1296,7 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* p) {
HasDescriptorMethods(descriptor_->file(), options_) ? "" : "Lite";
auto v = p->WithVars(std::move(vars));
format(
"class $classname$ : public "
"class $classname$ final : public "
"::$proto_ns$::internal::MapEntry$lite$<$classname$, \n"
" $key_cpp$, $val_cpp$,\n"
" ::$proto_ns$::internal::WireFormatLite::$key_wire_type$,\n"

@ -191,17 +191,6 @@ bool IsFieldEligibleForFastParsing(
int aux_idx = entry.aux_idx;
switch (field->type()) {
case FieldDescriptor::TYPE_ENUM:
// If enum values are not validated at parse time, then this field can be
// handled on the fast path like an int32.
if (cpp::HasPreservingUnknownEnumSemantics(field)) {
break;
}
if (field->is_repeated() && field->is_packed()) {
return false;
}
break;
// Some bytes fields can be handled on fast path.
case FieldDescriptor::TYPE_STRING:
case FieldDescriptor::TYPE_BYTES:

@ -662,6 +662,7 @@ class PROTOBUF_EXPORT TcParser final {
// For FindFieldEntry tests:
friend class FindFieldEntryTest;
friend struct ParseFunctionGeneratorTestPeer;
friend struct FuzzPeer;
static constexpr const uint32_t kMtSmallScanSize = 4;
// Mini parsing:

@ -254,7 +254,7 @@ absl::string_view TcParser::FieldName(const TcParseTableBase* table,
field_index + 1);
}
const char* TcParser::MiniParse(PROTOBUF_TC_PARAM_DECL) {
PROTOBUF_NOINLINE const char* TcParser::MiniParse(PROTOBUF_TC_PARAM_DECL) {
uint32_t tag;
ptr = ReadTagInlined(ptr, &tag);
if (PROTOBUF_PREDICT_FALSE(ptr == nullptr)) {

@ -222,6 +222,7 @@ class UntypedMessage final {
} else {
GOOGLE_CHECK(false) << "wrong type for UntypedMessage::Get(" << field_number
<< ")";
return {}; // avoid compiler warning.
}
}

@ -103,7 +103,7 @@ struct MoveHelper<false, false, true, T> { // strings and similar
};
// MapEntryImpl is used to implement parsing and serialization of map entries.
// It uses Curious Recursive Template Pattern (CRTP) to provide the type of
// It uses Curiously Recurring Template Pattern (CRTP) to provide the type of
// the eventual code to the template code.
template <typename Derived, typename Base, typename Key, typename Value,
WireFormatLite::FieldType kKeyFieldType,
@ -171,10 +171,10 @@ class MapEntryImpl : public Base {
// accessors ======================================================
virtual inline const KeyMapEntryAccessorType& key() const {
inline const KeyMapEntryAccessorType& key() const {
return KeyTypeHandler::GetExternalReference(key_);
}
virtual inline const ValueMapEntryAccessorType& value() const {
inline const ValueMapEntryAccessorType& value() const {
return ValueTypeHandler::DefaultIfNotInitialized(value_);
}
inline KeyMapEntryAccessorType* mutable_key() {
@ -429,10 +429,14 @@ class MapEntryImpl : public Base {
typedef void DestructorSkippable_;
template <typename C, typename K, typename V, WireFormatLite::FieldType,
WireFormatLite::FieldType>
friend class internal::MapEntry;
friend class ::PROTOBUF_NAMESPACE_ID::internal::MapEntry;
template <typename C, typename K, typename V, WireFormatLite::FieldType,
WireFormatLite::FieldType>
friend class internal::MapFieldLite;
friend class ::PROTOBUF_NAMESPACE_ID::internal::MapFieldLite;
template <typename DerivedT, typename KeyT, typename TT,
WireFormatLite::FieldType, WireFormatLite::FieldType>
friend class ::PROTOBUF_NAMESPACE_ID::internal::MapField;
};
template <typename T, typename Key, typename Value,

@ -157,6 +157,7 @@ class MapIterator;
class MapReflectionTester;
namespace internal {
struct FuzzPeer;
struct DescriptorTable;
class MapFieldBase;
class SwapFieldHelper;
@ -1110,6 +1111,7 @@ class PROTOBUF_EXPORT Reflection final {
friend class internal::WireFormat;
friend class internal::ReflectionOps;
friend class internal::SwapFieldHelper;
friend struct internal::FuzzPeer;
// Needed for implementing text format for map.
friend class internal::MapFieldPrinterHelper;

@ -973,6 +973,13 @@
// Protobuf does not support building with a number of warnings that are noisy
// (and of variable quality across compiler versions) or impossible to implement
// effectively but which people turn on anyways.
#ifdef __clang__
#pragma clang diagnostic push
// -Wshorten-64-to-32 is a typical pain where we diff pointers.
// char* p = strchr(s, '\n');
// return p ? p - s : -1;
#pragma clang diagnostic ignored "-Wshorten-64-to-32"
#endif
#ifdef __GNUC__
#pragma GCC diagnostic push
// Some of the warnings below only exist in some GCC versions; those version
@ -982,16 +989,20 @@
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60875, so we disable this one
// globally even though it's only used for PROTOBUF_FIELD_OFFSET.
#pragma GCC diagnostic ignored "-Winvalid-offsetof"
// This warning verifies that non-void-returning functions return a value in
// all paths. However, this warning is noisy, and requires adding unnecessary
// returns in unreachable positions.
#pragma GCC diagnostic ignored "-Wreturn-type"
#ifdef __clang__
// TODO(b/255348263): Upgrade our kokoro Ubuntu to use clang 6, then change th 5 to a 6
static_assert(PROTOBUF_CLANG_MIN(5, 0), "Protobuf only supports Clang 6.0 and newer.");
#endif
// Some versions of GCC seem to think that
// [this] { Foo(); }
// leaves `this` unused, even though `Foo();` is a member function of the
// captured `this`.
// https://bugzilla.mozilla.org/show_bug.cgi?id=1373625
#pragma GCC diagnostic ignored "-Wunused-lambda-capture"
// -Wsign-conversion causes a lot of warnings on mostly code like:
// int index = ...
// int value = vec[index];
#pragma GCC diagnostic ignored "-Wsign-conversion"
#endif // __GNUC__
// Silence some MSVC warnings in all our code.

@ -182,6 +182,10 @@
#pragma GCC diagnostic pop
#endif
#ifdef __clang__
#pragma clang diagnostic pop
#endif
// Pop the warning(push) from port_def.inc
#ifdef _MSC_VER
#pragma warning(pop)

@ -994,6 +994,14 @@ message TestDynamicExtensions {
repeated sint32 packed_extension = 2006 [packed = true];
}
message TestRepeatedString {
repeated string repeated_string1 = 1;
repeated string repeated_string2 = 2;
repeated bytes repeated_bytes11 = 11;
repeated bytes repeated_bytes12 = 12;
}
message TestRepeatedScalarDifferentTagSizes {
// Parsing repeated fixed size values used to fail. This message needs to be
// used in order to get a tag of the right size; all of the repeated fields

Loading…
Cancel
Save