diff --git a/java/core/BUILD.bazel b/java/core/BUILD.bazel index 5a5eed9725..9207a552fd 100644 --- a/java/core/BUILD.bazel +++ b/java/core/BUILD.bazel @@ -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", diff --git a/java/core/generate-test-sources-build.xml b/java/core/generate-test-sources-build.xml index bad6f19c61..68edf0bfc5 100644 --- a/java/core/generate-test-sources-build.xml +++ b/java/core/generate-test-sources-build.xml @@ -43,8 +43,10 @@ + + diff --git a/java/core/src/main/java/com/google/protobuf/AbstractMessage.java b/java/core/src/main/java/com/google/protobuf/AbstractMessage.java index bbfb965024..d8efa59f11 100644 --- a/java/core/src/main/java/com/google/protobuf/AbstractMessage.java +++ b/java/core/src/main/java/com/google/protobuf/AbstractMessage.java @@ -83,7 +83,6 @@ public abstract class AbstractMessage throw new UnsupportedOperationException("Nested builder is not supported for this type."); } - @Override public List 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. diff --git a/java/core/src/main/java/com/google/protobuf/AbstractMessageLite.java b/java/core/src/main/java/com/google/protobuf/AbstractMessageLite.java index 7ad2a85cf0..d7833da013 100644 --- a/java/core/src/main/java/com/google/protobuf/AbstractMessageLite.java +++ b/java/core/src/main/java/com/google/protobuf/AbstractMessageLite.java @@ -106,7 +106,6 @@ public abstract class AbstractMessageLite< throw new UnsupportedOperationException(); } - int getSerializedSize(Schema schema) { int memoizedSerializedSize = getMemoizedSerializedSize(); if (memoizedSerializedSize == -1) { diff --git a/java/core/src/main/java/com/google/protobuf/CodedInputStream.java b/java/core/src/main/java/com/google/protobuf/CodedInputStream.java index b3074b5b55..7912d4c55f 100644 --- a/java/core/src/main/java/com/google/protobuf/CodedInputStream.java +++ b/java/core/src/main/java/com/google/protobuf/CodedInputStream.java @@ -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 readGroup( final int fieldNumber, final Parser 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 readMessage( final Parser 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 readGroup( final int fieldNumber, @@ -878,7 +873,6 @@ public abstract class CodedInputStream { popLimit(oldLimit); } - @Override public T readMessage( final Parser 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 readGroup( final int fieldNumber, @@ -1598,7 +1590,6 @@ public abstract class CodedInputStream { popLimit(oldLimit); } - @Override public T readMessage( final Parser 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 readGroup( final int fieldNumber, @@ -2398,7 +2387,6 @@ public abstract class CodedInputStream { popLimit(oldLimit); } - @Override public T readMessage( final Parser parser, final ExtensionRegistryLite extensionRegistry) throws IOException { @@ -3454,7 +3442,6 @@ public abstract class CodedInputStream { --recursionDepth; } - @Override public T readGroup( final int fieldNumber, @@ -3493,7 +3480,6 @@ public abstract class CodedInputStream { popLimit(oldLimit); } - @Override public T readMessage( final Parser parser, final ExtensionRegistryLite extensionRegistry) throws IOException { diff --git a/java/core/src/main/java/com/google/protobuf/Descriptors.java b/java/core/src/main/java/com/google/protobuf/Descriptors.java index 91c9b1977f..939c70e659 100644 --- a/java/core/src/main/java/com/google/protobuf/Descriptors.java +++ b/java/core/src/main/java/com/google/protobuf/Descriptors.java @@ -1728,7 +1728,6 @@ public final class Descriptors { // down-cast and call mergeFrom directly. return ((Message.Builder) to).mergeFrom((Message) from); } - } // ================================================================= diff --git a/java/core/src/main/java/com/google/protobuf/DynamicMessage.java b/java/core/src/main/java/com/google/protobuf/DynamicMessage.java index 87d85a5e4b..738c30392d 100644 --- a/java/core/src/main/java/com/google/protobuf/DynamicMessage.java +++ b/java/core/src/main/java/com/google/protobuf/DynamicMessage.java @@ -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 { diff --git a/java/core/src/main/java/com/google/protobuf/ExtensionRegistry.java b/java/core/src/main/java/com/google/protobuf/ExtensionRegistry.java index f0f15641f1..d5acc4aeb9 100644 --- a/java/core/src/main/java/com/google/protobuf/ExtensionRegistry.java +++ b/java/core/src/main/java/com/google/protobuf/ExtensionRegistry.java @@ -99,7 +99,6 @@ public class ExtensionRegistry extends ExtensionRegistryLite { return EMPTY_REGISTRY; } - /** Returns an unmodifiable view of the registry. */ @Override public ExtensionRegistry getUnmodifiable() { diff --git a/java/core/src/main/java/com/google/protobuf/ExtensionRegistryFactory.java b/java/core/src/main/java/com/google/protobuf/ExtensionRegistryFactory.java index 0a63fad187..c51c6dd64c 100644 --- a/java/core/src/main/java/com/google/protobuf/ExtensionRegistryFactory.java +++ b/java/core/src/main/java/com/google/protobuf/ExtensionRegistryFactory.java @@ -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()); diff --git a/java/core/src/main/java/com/google/protobuf/ExtensionRegistryLite.java b/java/core/src/main/java/com/google/protobuf/ExtensionRegistryLite.java index 4b2aa07628..4166871b40 100644 --- a/java/core/src/main/java/com/google/protobuf/ExtensionRegistryLite.java +++ b/java/core/src/main/java/com/google/protobuf/ExtensionRegistryLite.java @@ -138,7 +138,6 @@ public class ExtensionRegistryLite { return result; } - /** Returns an unmodifiable view of the registry. */ public ExtensionRegistryLite getUnmodifiable() { return new ExtensionRegistryLite(this); diff --git a/java/core/src/main/java/com/google/protobuf/FieldSet.java b/java/core/src/main/java/com/google/protobuf/FieldSet.java index 9b294e33a7..7bb3c9aadf 100644 --- a/java/core/src/main/java/com/google/protobuf/FieldSet.java +++ b/java/core/src/main/java/com/google/protobuf/FieldSet.java @@ -185,7 +185,6 @@ final class FieldSet> { return clone; } - // ================================================================= /** See {@link Message.Builder#clear()}. */ @@ -574,7 +573,6 @@ final class FieldSet> { } } - /** See {@link Message#writeTo(CodedOutputStream)}. */ public void writeTo(final CodedOutputStream output) throws IOException { for (int i = 0; i < fields.getNumArrayEntries(); i++) { diff --git a/java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java b/java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java index ac975b9ff1..56a6fc3819 100644 --- a/java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java +++ b/java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java @@ -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}. * 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 41ea0a11ba..c1079367d1 100644 --- a/java/core/src/main/java/com/google/protobuf/GeneratedMessageV3.java +++ b/java/core/src/main/java/com/google/protobuf/GeneratedMessageV3.java @@ -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> extends AbstractMessage.Builder { @@ -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 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. */ 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 0fb934f9e3..7a7270b8c3 100644 --- a/java/core/src/main/java/com/google/protobuf/Internal.java +++ b/java/core/src/main/java/com/google/protobuf/Internal.java @@ -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); } - } diff --git a/java/core/src/main/java/com/google/protobuf/MapField.java b/java/core/src/main/java/com/google/protobuf/MapField.java index 2fe8867a74..ee9c5ad39f 100644 --- a/java/core/src/main/java/com/google/protobuf/MapField.java +++ b/java/core/src/main/java/com/google/protobuf/MapField.java @@ -122,7 +122,6 @@ public class MapField implements MutabilityOracle { } } - private final Converter converter; private MapField(Converter converter, StorageMode mode, Map mapData) { @@ -137,19 +136,16 @@ public class MapField implements MutabilityOracle { this(new ImmutableMessageConverter(defaultEntry), mode, mapData); } - /** Returns an immutable empty MapField. */ public static MapField emptyMapField(MapEntry defaultEntry) { return new MapField(defaultEntry, StorageMode.MAP, Collections.emptyMap()); } - /** Creates a new mutable empty MapField. */ public static MapField newMapField(MapEntry defaultEntry) { return new MapField(defaultEntry, StorageMode.MAP, new LinkedHashMap()); } - private Message convertKeyAndValueToMessage(K key, V value) { return converter.convertKeyAndValueToMessage(key, value); } diff --git a/java/core/src/main/java/com/google/protobuf/Message.java b/java/core/src/main/java/com/google/protobuf/Message.java index f641739e32..38355864d4 100644 --- a/java/core/src/main/java/com/google/protobuf/Message.java +++ b/java/core/src/main/java/com/google/protobuf/Message.java @@ -51,7 +51,6 @@ public interface Message extends MessageLite, MessageOrBuilder { @Override Parser getParserForType(); - // ----------------------------------------------------------------- // Comparison and hashing diff --git a/java/core/src/main/java/com/google/protobuf/MessageLite.java b/java/core/src/main/java/com/google/protobuf/MessageLite.java index d6314691be..a6228758cf 100644 --- a/java/core/src/main/java/com/google/protobuf/MessageLite.java +++ b/java/core/src/main/java/com/google/protobuf/MessageLite.java @@ -123,7 +123,6 @@ public interface MessageLite extends MessageLiteOrBuilder { */ void writeDelimitedTo(OutputStream output) throws IOException; - // ================================================================= // Builders diff --git a/java/core/src/main/java/com/google/protobuf/MessageReflection.java b/java/core/src/main/java/com/google/protobuf/MessageReflection.java index 294d841774..0404042019 100644 --- a/java/core/src/main/java/com/google/protobuf/MessageReflection.java +++ b/java/core/src/main/java/com/google/protobuf/MessageReflection.java @@ -673,7 +673,6 @@ class MessageReflection { } } - static class ExtensionAdapter implements MergeTarget { private final FieldSet extensions; diff --git a/java/core/src/main/java/com/google/protobuf/TextFormat.java b/java/core/src/main/java/com/google/protobuf/TextFormat.java index 9b3c3569b6..cd98518d11 100644 --- a/java/core/src/main/java/com/google/protobuf/TextFormat.java +++ b/java/core/src/main/java/com/google/protobuf/TextFormat.java @@ -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, diff --git a/java/core/src/main/java/com/google/protobuf/TypeRegistry.java b/java/core/src/main/java/com/google/protobuf/TypeRegistry.java index 422ff1f870..3a9461f152 100644 --- a/java/core/src/main/java/com/google/protobuf/TypeRegistry.java +++ b/java/core/src/main/java/com/google/protobuf/TypeRegistry.java @@ -55,7 +55,6 @@ public class TypeRegistry { return EmptyTypeRegistryHolder.EMPTY; } - public static Builder newBuilder() { return new Builder(); } diff --git a/java/core/src/main/java/com/google/protobuf/UnknownFieldSet.java b/java/core/src/main/java/com/google/protobuf/UnknownFieldSet.java index 45b5a6b306..d27d0b5f69 100644 --- a/java/core/src/main/java/com/google/protobuf/UnknownFieldSet.java +++ b/java/core/src/main/java/com/google/protobuf/UnknownFieldSet.java @@ -89,7 +89,6 @@ public final class UnknownFieldSet implements MessageLite { private static final UnknownFieldSet defaultInstance = new UnknownFieldSet(new TreeMap()); - @Override public boolean equals(Object other) { if (this == other) { diff --git a/java/core/src/main/java/com/google/protobuf/UnsafeByteOperations.java b/java/core/src/main/java/com/google/protobuf/UnsafeByteOperations.java index be6f97de75..164010e438 100644 --- a/java/core/src/main/java/com/google/protobuf/UnsafeByteOperations.java +++ b/java/core/src/main/java/com/google/protobuf/UnsafeByteOperations.java @@ -117,5 +117,4 @@ public final class UnsafeByteOperations { public static void unsafeWriteTo(ByteString bytes, ByteOutput output) throws IOException { bytes.writeTo(output); } - } diff --git a/java/core/src/test/java/com/google/protobuf/AnyTest.java b/java/core/src/test/java/com/google/protobuf/AnyTest.java index ee13ef1560..ac047a9cf9 100644 --- a/java/core/src/test/java/com/google/protobuf/AnyTest.java +++ b/java/core/src/test/java/com/google/protobuf/AnyTest.java @@ -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); diff --git a/java/core/src/test/java/com/google/protobuf/CodedInputStreamTest.java b/java/core/src/test/java/com/google/protobuf/CodedInputStreamTest.java index db3a0c26d2..12ff6ddede 100644 --- a/java/core/src/test/java/com/google/protobuf/CodedInputStreamTest.java +++ b/java/core/src/test/java/com/google/protobuf/CodedInputStreamTest.java @@ -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 { diff --git a/java/core/src/test/java/com/google/protobuf/DescriptorsTest.java b/java/core/src/test/java/com/google/protobuf/DescriptorsTest.java index 7988e7cce6..ee119535b9 100644 --- a/java/core/src/test/java/com/google/protobuf/DescriptorsTest.java +++ b/java/core/src/test/java/com/google/protobuf/DescriptorsTest.java @@ -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 diff --git a/java/core/src/test/java/com/google/protobuf/FieldPresenceTest.java b/java/core/src/test/java/com/google/protobuf/FieldPresenceTest.java index c4830af392..b26c8099c5 100644 --- a/java/core/src/test/java/com/google/protobuf/FieldPresenceTest.java +++ b/java/core/src/test/java/com/google/protobuf/FieldPresenceTest.java @@ -500,5 +500,4 @@ public class FieldPresenceTest { assertThat(builder.isInitialized()).isTrue(); assertThat(builder.buildPartial().isInitialized()).isTrue(); } - } diff --git a/java/core/src/test/java/com/google/protobuf/GeneratedMessageTest.java b/java/core/src/test/java/com/google/protobuf/GeneratedMessageTest.java index 01c2f4b39a..3fc47c368e 100644 --- a/java/core/src/test/java/com/google/protobuf/GeneratedMessageTest.java +++ b/java/core/src/test/java/com/google/protobuf/GeneratedMessageTest.java @@ -801,7 +801,6 @@ public class GeneratedMessageTest { assertThat(fieldBuilder.build().getField(field)).isEqualTo(expected); } - @Test public void testGetBuilderForNonMessageExtensionField() { TestAllExtensions.Builder builder = TestAllExtensions.newBuilder(); diff --git a/java/core/src/test/java/com/google/protobuf/LazyFieldLiteTest.java b/java/core/src/test/java/com/google/protobuf/LazyFieldLiteTest.java index 98cee80405..953ff573f0 100644 --- a/java/core/src/test/java/com/google/protobuf/LazyFieldLiteTest.java +++ b/java/core/src/test/java/com/google/protobuf/LazyFieldLiteTest.java @@ -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(); } - } diff --git a/java/core/src/test/java/com/google/protobuf/MapForProto2Test.java b/java/core/src/test/java/com/google/protobuf/MapForProto2Test.java index 2f74f96ed2..0f08f9dd24 100644 --- a/java/core/src/test/java/com/google/protobuf/MapForProto2Test.java +++ b/java/core/src/test/java/com/google/protobuf/MapForProto2Test.java @@ -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 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 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 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 Map newMap(K key1, V value1) { Map map = new HashMap(); map.put(key1, value1); return map; } - // + private static Map newMap(K key1, V value1, K key2, V value2) { Map map = new HashMap(); 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) { diff --git a/java/core/src/test/java/com/google/protobuf/MapTest.java b/java/core/src/test/java/com/google/protobuf/MapTest.java index 1bb7166718..aca0b2ac85 100644 --- a/java/core/src/test/java/com/google/protobuf/MapTest.java +++ b/java/core/src/test/java/com/google/protobuf/MapTest.java @@ -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 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 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 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(); diff --git a/java/core/src/test/java/com/google/protobuf/ParserTest.java b/java/core/src/test/java/com/google/protobuf/ParserTest.java index 69c5795c1f..510374fc61 100644 --- a/java/core/src/test/java/com/google/protobuf/ParserTest.java +++ b/java/core/src/test/java/com/google/protobuf/ParserTest.java @@ -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(); 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 ad512a9036..39cf822160 100644 --- a/java/core/src/test/java/com/google/protobuf/TestBadIdentifiers.java +++ b/java/core/src/test/java/com/google/protobuf/TestBadIdentifiers.java @@ -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()); - } } diff --git a/java/core/src/test/java/com/google/protobuf/TextFormatPerformanceTest.java b/java/core/src/test/java/com/google/protobuf/TextFormatPerformanceTest.java new file mode 100644 index 0000000000..94e51be057 --- /dev/null +++ b/java/core/src/test/java/com/google/protobuf/TextFormatPerformanceTest.java @@ -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); + } + } +} 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 1a76848d68..cf0061e637 100644 --- a/java/core/src/test/java/com/google/protobuf/TextFormatTest.java +++ b/java/core/src/test/java/com/google/protobuf/TextFormatTest.java @@ -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"); } - } diff --git a/java/core/src/test/java/com/google/protobuf/TypeRegistryTest.java b/java/core/src/test/java/com/google/protobuf/TypeRegistryTest.java index c9defb3c93..29ecf9280a 100644 --- a/java/core/src/test/java/com/google/protobuf/TypeRegistryTest.java +++ b/java/core/src/test/java/com/google/protobuf/TypeRegistryTest.java @@ -65,5 +65,4 @@ public final class TypeRegistryTest { .getDescriptorForTypeUrl("type.googleapis.com/" + descriptor.getFullName())) .isSameInstanceAs(descriptor); } - } diff --git a/java/core/src/test/proto/com/google/protobuf/proto2_text_format_performance_test.proto b/java/core/src/test/proto/com/google/protobuf/proto2_text_format_performance_test.proto new file mode 100644 index 0000000000..2f5431d7e6 --- /dev/null +++ b/java/core/src/test/proto/com/google/protobuf/proto2_text_format_performance_test.proto @@ -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; +} diff --git a/java/core/src/test/proto/com/google/protobuf/proto3_text_format_performance_test.proto b/java/core/src/test/proto/com/google/protobuf/proto3_text_format_performance_test.proto new file mode 100644 index 0000000000..a3c19623be --- /dev/null +++ b/java/core/src/test/proto/com/google/protobuf/proto3_text_format_performance_test.proto @@ -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; +} diff --git a/java/internal/JavaVersionTest.java b/java/internal/JavaVersionTest.java index eb004d5bd9..c7957c0d81 100644 --- a/java/internal/JavaVersionTest.java +++ b/java/internal/JavaVersionTest.java @@ -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; diff --git a/java/lite/pom.xml b/java/lite/pom.xml index 69bd30cc09..8075e75efd 100644 --- a/java/lite/pom.xml +++ b/java/lite/pom.xml @@ -229,6 +229,7 @@ TestBadIdentifiers.java TextFormatParseInfoTreeTest.java TextFormatParseLocationTest.java + TextFormatPerformanceTest.java TextFormatTest.java TestUtil.java TypeRegistryTest.java diff --git a/java/lite/src/test/java/com/google/protobuf/LiteTest.java b/java/lite/src/test/java/com/google/protobuf/LiteTest.java index ee21b3774c..a4f95a2666 100644 --- a/java/lite/src/test/java/com/google/protobuf/LiteTest.java +++ b/java/lite/src/test/java/com/google/protobuf/LiteTest.java @@ -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 = diff --git a/java/util/src/main/java/com/google/protobuf/util/JsonFormat.java b/java/util/src/main/java/com/google/protobuf/util/JsonFormat.java index 6bed2e34d8..992980b0dc 100644 --- a/java/util/src/main/java/com/google/protobuf/util/JsonFormat.java +++ b/java/util/src/main/java/com/google/protobuf/util/JsonFormat.java @@ -534,7 +534,6 @@ public class JsonFormat { this.types = types; } - /** A Builder is used to build {@link TypeRegistry}. */ public static class Builder { private Builder() {} diff --git a/java/util/src/test/java/com/google/protobuf/util/JsonFormatTest.java b/java/util/src/test/java/com/google/protobuf/util/JsonFormatTest.java index c31031edb1..45ae68ac03 100644 --- a/java/util/src/test/java/com/google/protobuf/util/JsonFormatTest.java +++ b/java/util/src/test/java/com/google/protobuf/util/JsonFormatTest.java @@ -1019,7 +1019,6 @@ public class JsonFormatTest { assertRoundTripEquals(message); } - @Test public void testAnyFieldsWithCustomAddedTypeRegistry() throws Exception { TestAllTypes content = TestAllTypes.newBuilder().setOptionalInt32(1234).build(); diff --git a/java/util/src/test/java/com/google/protobuf/util/StructsTest.java b/java/util/src/test/java/com/google/protobuf/util/StructsTest.java index 9eb4cc61ec..b57a11679c 100644 --- a/java/util/src/test/java/com/google/protobuf/util/StructsTest.java +++ b/java/util/src/test/java/com/google/protobuf/util/StructsTest.java @@ -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()); } - } diff --git a/python/google/protobuf/internal/descriptor_pool_test.py b/python/google/protobuf/internal/descriptor_pool_test.py index d8c1ecf4d9..9b102704ac 100644 --- a/python/google/protobuf/internal/descriptor_pool_test.py +++ b/python/google/protobuf/internal/descriptor_pool_test.py @@ -56,7 +56,6 @@ from google.protobuf import message_factory from google.protobuf import symbol_database - warnings.simplefilter('error', DeprecationWarning) diff --git a/python/google/protobuf/internal/message_test.py b/python/google/protobuf/internal/message_test.py index 3c604dd31d..a83cf85dea 100644 --- a/python/google/protobuf/internal/message_test.py +++ b/python/google/protobuf/internal/message_test.py @@ -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): diff --git a/python/google/protobuf/internal/reflection_test.py b/python/google/protobuf/internal/reflection_test.py index 62957d3fde..f35e514dd2 100644 --- a/python/google/protobuf/internal/reflection_test.py +++ b/python/google/protobuf/internal/reflection_test.py @@ -3220,7 +3220,6 @@ class OptionsTest(unittest.TestCase): field_descriptor.label) - @testing_refleaks.TestCase class ClassAPITest(unittest.TestCase): diff --git a/python/google/protobuf/internal/text_format_test.py b/python/google/protobuf/internal/text_format_test.py index 996ef65a3e..5f2c2deaf5 100644 --- a/python/google/protobuf/internal/text_format_test.py +++ b/python/google/protobuf/internal/text_format_test.py @@ -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() diff --git a/src/google/protobuf/arena_unittest.cc b/src/google/protobuf/arena_unittest.cc index 8d76d7f205..3539c18922 100644 --- a/src/google/protobuf/arena_unittest.cc +++ b/src/google/protobuf/arena_unittest.cc @@ -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 { diff --git a/src/google/protobuf/arenastring.cc b/src/google/protobuf/arenastring.cc index f033d6728a..9a0a223825 100644 --- a/src/google/protobuf/arenastring.cc +++ b/src/google/protobuf/arenastring.cc @@ -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()) { diff --git a/src/google/protobuf/arenastring.h b/src/google/protobuf/arenastring.h index 519e50d00c..0d093e5450 100644 --- a/src/google/protobuf/arenastring.h +++ b/src/google/protobuf/arenastring.h @@ -262,11 +262,15 @@ struct PROTOBUF_EXPORT ArenaStringPtr { void Set(absl::string_view value, Arena* arena); void Set(std::string&& value, Arena* arena); + template + 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 + 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); } diff --git a/src/google/protobuf/compiler/cpp/field.cc b/src/google/protobuf/compiler/cpp/field.cc index 3199dce889..1ec6bf7421 100644 --- a/src/google/protobuf/compiler/cpp/field.cc +++ b/src/google/protobuf/compiler/cpp/field.cc @@ -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; } diff --git a/src/google/protobuf/compiler/cpp/file.cc b/src/google/protobuf/compiler/cpp/file.cc index 3ead83e968..d3dac8b113 100644 --- a/src/google/protobuf/compiler/cpp/file.cc +++ b/src/google/protobuf/compiler/cpp/file.cc @@ -112,7 +112,7 @@ FileGenerator::FileGenerator(const FileDescriptor* file, const Options& options) std::vector msgs = FlattenMessagesInFile(file); for (int i = 0; i < msgs.size(); ++i) { - message_generators_.push_back(absl::make_unique( + message_generators_.push_back(std::make_unique( 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(file->enum_type(i), options)); + std::make_unique(file->enum_type(i), options)); } for (int i = 0; i < file->service_count(); ++i) { - service_generators_.push_back(absl::make_unique( + service_generators_.push_back(std::make_unique( 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( + extension_generators_.push_back(std::make_unique( file->extension(i), options, &scc_analyzer_)); } diff --git a/src/google/protobuf/compiler/cpp/message.cc b/src/google/protobuf/compiler/cpp/message.cc index 38f60946eb..51f94d10be 100644 --- a/src/google/protobuf/compiler/cpp/message.cc +++ b/src/google/protobuf/compiler/cpp/message.cc @@ -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" diff --git a/src/google/protobuf/generated_message_tctable_gen.cc b/src/google/protobuf/generated_message_tctable_gen.cc index febf77fc37..11ae866455 100644 --- a/src/google/protobuf/generated_message_tctable_gen.cc +++ b/src/google/protobuf/generated_message_tctable_gen.cc @@ -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: diff --git a/src/google/protobuf/generated_message_tctable_impl.h b/src/google/protobuf/generated_message_tctable_impl.h index 24615b2df6..86032ef2c8 100644 --- a/src/google/protobuf/generated_message_tctable_impl.h +++ b/src/google/protobuf/generated_message_tctable_impl.h @@ -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: diff --git a/src/google/protobuf/generated_message_tctable_lite.cc b/src/google/protobuf/generated_message_tctable_lite.cc index ea8f4fb005..cfa6c9371f 100644 --- a/src/google/protobuf/generated_message_tctable_lite.cc +++ b/src/google/protobuf/generated_message_tctable_lite.cc @@ -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)) { diff --git a/src/google/protobuf/json/internal/untyped_message.h b/src/google/protobuf/json/internal/untyped_message.h index 1b4ad8fbaf..ba549c1a2c 100644 --- a/src/google/protobuf/json/internal/untyped_message.h +++ b/src/google/protobuf/json/internal/untyped_message.h @@ -222,6 +222,7 @@ class UntypedMessage final { } else { GOOGLE_CHECK(false) << "wrong type for UntypedMessage::Get(" << field_number << ")"; + return {}; // avoid compiler warning. } } diff --git a/src/google/protobuf/map_entry_lite.h b/src/google/protobuf/map_entry_lite.h index 78ed4f2508..be11257260 100644 --- a/src/google/protobuf/map_entry_lite.h +++ b/src/google/protobuf/map_entry_lite.h @@ -103,7 +103,7 @@ struct MoveHelper { // 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 - friend class internal::MapEntry; + friend class ::PROTOBUF_NAMESPACE_ID::internal::MapEntry; template - friend class internal::MapFieldLite; + friend class ::PROTOBUF_NAMESPACE_ID::internal::MapFieldLite; + + template + friend class ::PROTOBUF_NAMESPACE_ID::internal::MapField; }; template