diff --git a/.bazelrc b/.bazelrc index 554440cfe3..de30d6b48c 100644 --- a/.bazelrc +++ b/.bazelrc @@ -1 +1,35 @@ build --cxxopt=-std=c++14 --host_cxxopt=-std=c++14 + +build:dbg --compilation_mode=dbg + +build:opt --compilation_mode=opt + +build:san-common --config=dbg --strip=never --copt=-O0 --copt=-fno-omit-frame-pointer + +build:asan --config=san-common --copt=-fsanitize=address --linkopt=-fsanitize=address +build:asan --copt=-DADDRESS_SANITIZER=1 +# ASAN hits ODR violations with shared linkage due to rules_proto. +build:asan --dynamic_mode=off + +build:msan --config=san-common --copt=-fsanitize=memory --linkopt=-fsanitize=memory +build:msan --copt=-fsanitize-memory-track-origins +build:msan --copt=-fsanitize-memory-use-after-dtor +build:msan --action_env=MSAN_OPTIONS=poison_in_dtor=1 +build:msan --copt=-DMEMORY_SANITIZER=1 + +# Use our instrumented LLVM libc++ in Kokoro. +build:kokoro-msan --config=msan +build:kokoro-msan --linkopt=-L/opt/libcxx_msan/lib +build:kokoro-msan --linkopt=-Wl,-rpath,/opt/libcxx_msan/lib +build:kokoro-msan --cxxopt=-stdlib=libc++ --linkopt=-stdlib=libc++ + + +build:tsan --config=san-common --copt=-fsanitize=thread --linkopt=-fsanitize=thread +build:tsan --copt=-DTHREAD_SANITIZER=1 + +build:ubsan --config=san-common --copt=-fsanitize=undefined --linkopt=-fsanitize=undefined +build:ubsan --action_env=UBSAN_OPTIONS=halt_on_error=1:print_stacktrace=1 +build:ubsan --copt=-DUNDEFINED_SANITIZER=1 +# Workaround for the fact that Bazel links with $CC, not $CXX +# https://github.com/bazelbuild/bazel/issues/11122#issuecomment-613746748 +build:ubsan --copt=-fno-sanitize=function --copt=-fno-sanitize=vptr diff --git a/CHANGES.txt b/CHANGES.txt index c110dcbffe..52eee948ef 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -37,6 +37,12 @@ * Introduce the Printer::{SetRedactDebugString,SetRandomizeDebugString} private flags. * Introduce global flags to control Printer::{SetRedactDebugString, SetRandomizeDebugString}. * proto3 string fields no longer trigger clang-tidy warning bugprone-branch-clone. + * Fix the API of DescriptorUpgrader::set_allow_unknown_dependencies to set to True always, and to populate into the DescriptorPool as well. + * Report line numbers consistently in text-format deprecated-field warnings. + * Reserve C++20 keywords + * Fixed C++ code generation for protos that use int32_t, uint32_t, int64_t, uint64_t, size_t as field names. + * Annotate generated C++ public aliases for enum types. + * Change default arena max block size from 8K to 32K. Kotlin @@ -57,6 +63,12 @@ * Make message-type extensions merge from wire-format instead of building up instances and merging afterwards. This has much better performance. * Change the Lite runtime to prefer merging from the wireformat into mutable messages rather than building up a new immutable object before merging. This way results in fewer allocations and copy operations. * Move proto wireformat parsing functionality from the private "parsing constructor" to the Builder class. + * Refactoring java full runtime to reuse sub-message builders and prepare to migrate parsing logic from parse constructor to builder. + * Move proto wireformat parsing functionality from the private "parsing constructor" to the Builder class. + * Change the Lite runtime to prefer merging from the wireformat into mutable messages rather than building up a new immutable object before merging. This way results in fewer allocations and copy operations. + * Make message-type extensions merge from wire-format instead of building up instances and merging afterwards. This has much better performance. + * Fix TextFormat parser to build up recurring (but supposedly not repeated) sub-messages directly from text rather than building a new sub-message and merging the fully formed message into the existing field. + * Fix bug in nested builder caching logic where cleared sub-field builders would remain dirty after a clear and build in a parent layer. https://github.com/protocolbuffers/protobuf/issues/10624 Python * Changes ordering of printed fields in .pyi files from lexicographic to the same ordering found in the proto descriptor. @@ -66,6 +78,7 @@ Compiler * Print full path name of source .proto file on error + * Include proto message type in the annotation comments. 2022-10-18 version 21.8 (C++/Java/Python/PHP/Objective-C/C#/Ruby) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6c91c7b447..d490527747 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,6 +23,10 @@ endif() if(POLICY CMP0063) cmake_policy(SET CMP0063 NEW) endif() +# option() honor variables +if (POLICY CMP0077) + cmake_policy(SET CMP0077 NEW) +endif (POLICY CMP0077) # Project project(protobuf C CXX) diff --git a/Protobuf-C++.podspec b/Protobuf-C++.podspec index 55d6d1b403..54a962d13e 100644 --- a/Protobuf-C++.podspec +++ b/Protobuf-C++.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'Protobuf-C++' - s.version = '3.21.7' + s.version = '3.21.8' s.summary = 'Protocol Buffers v3 runtime library for C++.' s.homepage = 'https://github.com/google/protobuf' s.license = 'BSD-3-Clause' diff --git a/build_defs/cpp_opts.bzl b/build_defs/cpp_opts.bzl index 187435960f..912c19b3c0 100644 --- a/build_defs/cpp_opts.bzl +++ b/build_defs/cpp_opts.bzl @@ -14,14 +14,12 @@ COPTS = select({ "/wd4506", # no definition for inline function 'function' "/wd4800", # 'type' : forcing value to bool 'true' or 'false' (performance warning) "/wd4996", # The compiler encountered a deprecated declaration. - "/std:c++14", # Use C++14 ], "//conditions:default": [ "-DHAVE_ZLIB", "-Woverloaded-virtual", "-Wno-sign-compare", "-Werror", - "-std=c++14", # Protobuf requires C++14. ], }) diff --git a/cmake/protobuf-config.cmake.in b/cmake/protobuf-config.cmake.in index 1a8d243a74..44805c79a7 100644 --- a/cmake/protobuf-config.cmake.in +++ b/cmake/protobuf-config.cmake.in @@ -4,6 +4,7 @@ include("${CMAKE_CURRENT_LIST_DIR}/protobuf-options.cmake") # Depend packages @_protobuf_FIND_ZLIB@ @_protobuf_FIND_ABSL@ +@_protobuf_FIND_UTF8_RANGE@ # Imported targets include("${CMAKE_CURRENT_LIST_DIR}/protobuf-targets.cmake") diff --git a/cmake/utf8_range.cmake b/cmake/utf8_range.cmake index 90f5ff1ea5..4dcfa4bcca 100644 --- a/cmake/utf8_range.cmake +++ b/cmake/utf8_range.cmake @@ -1,4 +1,4 @@ -set(utf8_range_ENABLE_TESTS OFF) +set(utf8_range_ENABLE_TESTS OFF CACHE BOOL "Disable utf8_range tests") if (NOT EXISTS "${protobuf_SOURCE_DIR}/third_party/utf8_range/CMakeLists.txt") message(FATAL_ERROR @@ -8,5 +8,7 @@ if (NOT EXISTS "${protobuf_SOURCE_DIR}/third_party/utf8_range/CMakeLists.txt") " git submodule update --init --recursive\n") endif() -set(utf8_range_ENABLE_INSTALL ${protobuf_INSTALL}) -add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/third_party/utf8_range third_party/utf8_range) \ No newline at end of file +set(utf8_range_ENABLE_INSTALL ${protobuf_INSTALL} CACHE BOOL "Set install") +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/third_party/utf8_range third_party/utf8_range) + +set(_protobuf_FIND_UTF8_RANGE "if(NOT TARGET utf8_range)\n find_package(utf8_range CONFIG)\nendif()") diff --git a/csharp/.gitignore b/csharp/.gitignore index 62c96383ce..56ac1494d6 100644 --- a/csharp/.gitignore +++ b/csharp/.gitignore @@ -33,3 +33,8 @@ lib/protoc.exe # Benchmark output BenchmarkDotNet.Artifacts/ + +# Reinstate generated code for test files +!any_test.pb.* +!map*unittest.pb.* +!unittest*.pb.* diff --git a/csharp/build_release.sh b/csharp/build_release.sh index 1c3a9de002..8a641b21b3 100755 --- a/csharp/build_release.sh +++ b/csharp/build_release.sh @@ -7,4 +7,5 @@ set DOTNET_SKIP_FIRST_TIME_EXPERIENCE=true set DOTNET_CLI_TELEMETRY_OPTOUT=true # Builds Google.Protobuf NuGet packages +dotnet restore -s /lib/csharp/ src/Google.Protobuf/Google.Protobuf.csproj dotnet pack --no-restore -c Release src/Google.Protobuf.sln -p:ContinuousIntegrationBuild=true diff --git a/csharp/generate_protos.sh b/csharp/generate_protos.sh index cfd6082708..8be4428405 100755 --- a/csharp/generate_protos.sh +++ b/csharp/generate_protos.sh @@ -32,6 +32,7 @@ fi # descriptor.proto and well-known types $PROTOC -Isrc --csharp_out=csharp/src/Google.Protobuf \ --csharp_opt=base_namespace=Google.Protobuf \ + --csharp_opt=file_extension=.pb.cs \ src/google/protobuf/descriptor.proto \ src/google/protobuf/any.proto \ src/google/protobuf/api.proto \ @@ -52,6 +53,7 @@ $PROTOC -Isrc --csharp_out=csharp/src/Google.Protobuf \ $PROTOC -Isrc -Icsharp/protos \ --experimental_allow_proto3_optional \ --csharp_out=csharp/src/Google.Protobuf.Test.TestProtos \ + --csharp_opt=file_extension=.pb.cs \ --descriptor_set_out=csharp/src/Google.Protobuf.Test/testprotos.pb \ --include_source_info \ --include_imports \ @@ -75,4 +77,5 @@ $PROTOC -Isrc -Icsharp/protos \ # AddressBook sample protos $PROTOC -Iexamples -Isrc --csharp_out=csharp/src/AddressBook \ + --csharp_opt=file_extension=.pb.cs \ examples/addressbook.proto diff --git a/csharp/src/AddressBook/Addressbook.cs b/csharp/src/AddressBook/Addressbook.pb.cs similarity index 100% rename from csharp/src/AddressBook/Addressbook.cs rename to csharp/src/AddressBook/Addressbook.pb.cs diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/MapUnittestProto3.cs b/csharp/src/Google.Protobuf.Test.TestProtos/MapUnittestProto3.pb.cs similarity index 100% rename from csharp/src/Google.Protobuf.Test.TestProtos/MapUnittestProto3.cs rename to csharp/src/Google.Protobuf.Test.TestProtos/MapUnittestProto3.pb.cs diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/TestMessagesProto2.cs b/csharp/src/Google.Protobuf.Test.TestProtos/TestMessagesProto2.pb.cs similarity index 100% rename from csharp/src/Google.Protobuf.Test.TestProtos/TestMessagesProto2.cs rename to csharp/src/Google.Protobuf.Test.TestProtos/TestMessagesProto2.pb.cs diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/TestMessagesProto3.cs b/csharp/src/Google.Protobuf.Test.TestProtos/TestMessagesProto3.pb.cs similarity index 100% rename from csharp/src/Google.Protobuf.Test.TestProtos/TestMessagesProto3.cs rename to csharp/src/Google.Protobuf.Test.TestProtos/TestMessagesProto3.pb.cs diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/Unittest.cs b/csharp/src/Google.Protobuf.Test.TestProtos/Unittest.pb.cs similarity index 100% rename from csharp/src/Google.Protobuf.Test.TestProtos/Unittest.cs rename to csharp/src/Google.Protobuf.Test.TestProtos/Unittest.pb.cs diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestCustomOptionsProto3.cs b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestCustomOptionsProto3.pb.cs similarity index 100% rename from csharp/src/Google.Protobuf.Test.TestProtos/UnittestCustomOptionsProto3.cs rename to csharp/src/Google.Protobuf.Test.TestProtos/UnittestCustomOptionsProto3.pb.cs diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestImport.cs b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestImport.pb.cs similarity index 100% rename from csharp/src/Google.Protobuf.Test.TestProtos/UnittestImport.cs rename to csharp/src/Google.Protobuf.Test.TestProtos/UnittestImport.pb.cs diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestImportProto3.cs b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestImportProto3.pb.cs similarity index 100% rename from csharp/src/Google.Protobuf.Test.TestProtos/UnittestImportProto3.cs rename to csharp/src/Google.Protobuf.Test.TestProtos/UnittestImportProto3.pb.cs diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestImportPublic.cs b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestImportPublic.pb.cs similarity index 100% rename from csharp/src/Google.Protobuf.Test.TestProtos/UnittestImportPublic.cs rename to csharp/src/Google.Protobuf.Test.TestProtos/UnittestImportPublic.pb.cs diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestImportPublicProto3.cs b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestImportPublicProto3.pb.cs similarity index 100% rename from csharp/src/Google.Protobuf.Test.TestProtos/UnittestImportPublicProto3.cs rename to csharp/src/Google.Protobuf.Test.TestProtos/UnittestImportPublicProto3.pb.cs diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssue6936A.cs b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssue6936A.pb.cs similarity index 100% rename from csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssue6936A.cs rename to csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssue6936A.pb.cs diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssue6936B.cs b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssue6936B.pb.cs similarity index 100% rename from csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssue6936B.cs rename to csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssue6936B.pb.cs diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssue6936C.cs b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssue6936C.pb.cs similarity index 100% rename from csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssue6936C.cs rename to csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssue6936C.pb.cs diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssues.cs b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssues.pb.cs similarity index 100% rename from csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssues.cs rename to csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssues.pb.cs diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestProto3.cs b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestProto3.pb.cs similarity index 100% rename from csharp/src/Google.Protobuf.Test.TestProtos/UnittestProto3.cs rename to csharp/src/Google.Protobuf.Test.TestProtos/UnittestProto3.pb.cs diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestProto3Optional.cs b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestProto3Optional.pb.cs similarity index 100% rename from csharp/src/Google.Protobuf.Test.TestProtos/UnittestProto3Optional.cs rename to csharp/src/Google.Protobuf.Test.TestProtos/UnittestProto3Optional.pb.cs diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestSelfreferentialOptions.cs b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestSelfreferentialOptions.pb.cs similarity index 100% rename from csharp/src/Google.Protobuf.Test.TestProtos/UnittestSelfreferentialOptions.cs rename to csharp/src/Google.Protobuf.Test.TestProtos/UnittestSelfreferentialOptions.pb.cs diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestWellKnownTypes.cs b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestWellKnownTypes.pb.cs similarity index 100% rename from csharp/src/Google.Protobuf.Test.TestProtos/UnittestWellKnownTypes.cs rename to csharp/src/Google.Protobuf.Test.TestProtos/UnittestWellKnownTypes.pb.cs diff --git a/csharp/src/Google.Protobuf/Compiler/Plugin.cs b/csharp/src/Google.Protobuf/Compiler/Plugin.pb.cs similarity index 100% rename from csharp/src/Google.Protobuf/Compiler/Plugin.cs rename to csharp/src/Google.Protobuf/Compiler/Plugin.pb.cs diff --git a/csharp/src/Google.Protobuf/Reflection/Descriptor.cs b/csharp/src/Google.Protobuf/Reflection/Descriptor.pb.cs similarity index 100% rename from csharp/src/Google.Protobuf/Reflection/Descriptor.cs rename to csharp/src/Google.Protobuf/Reflection/Descriptor.pb.cs diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Any.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Any.pb.cs similarity index 100% rename from csharp/src/Google.Protobuf/WellKnownTypes/Any.cs rename to csharp/src/Google.Protobuf/WellKnownTypes/Any.pb.cs diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Api.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Api.pb.cs similarity index 100% rename from csharp/src/Google.Protobuf/WellKnownTypes/Api.cs rename to csharp/src/Google.Protobuf/WellKnownTypes/Api.pb.cs diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Duration.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Duration.pb.cs similarity index 100% rename from csharp/src/Google.Protobuf/WellKnownTypes/Duration.cs rename to csharp/src/Google.Protobuf/WellKnownTypes/Duration.pb.cs diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Empty.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Empty.pb.cs similarity index 100% rename from csharp/src/Google.Protobuf/WellKnownTypes/Empty.cs rename to csharp/src/Google.Protobuf/WellKnownTypes/Empty.pb.cs diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/FieldMask.cs b/csharp/src/Google.Protobuf/WellKnownTypes/FieldMask.pb.cs similarity index 100% rename from csharp/src/Google.Protobuf/WellKnownTypes/FieldMask.cs rename to csharp/src/Google.Protobuf/WellKnownTypes/FieldMask.pb.cs diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/SourceContext.cs b/csharp/src/Google.Protobuf/WellKnownTypes/SourceContext.pb.cs similarity index 100% rename from csharp/src/Google.Protobuf/WellKnownTypes/SourceContext.cs rename to csharp/src/Google.Protobuf/WellKnownTypes/SourceContext.pb.cs diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Struct.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Struct.pb.cs similarity index 100% rename from csharp/src/Google.Protobuf/WellKnownTypes/Struct.cs rename to csharp/src/Google.Protobuf/WellKnownTypes/Struct.pb.cs diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Timestamp.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Timestamp.pb.cs similarity index 100% rename from csharp/src/Google.Protobuf/WellKnownTypes/Timestamp.cs rename to csharp/src/Google.Protobuf/WellKnownTypes/Timestamp.pb.cs diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Type.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Type.pb.cs similarity index 100% rename from csharp/src/Google.Protobuf/WellKnownTypes/Type.cs rename to csharp/src/Google.Protobuf/WellKnownTypes/Type.pb.cs diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Wrappers.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Wrappers.pb.cs similarity index 100% rename from csharp/src/Google.Protobuf/WellKnownTypes/Wrappers.cs rename to csharp/src/Google.Protobuf/WellKnownTypes/Wrappers.pb.cs diff --git a/docs/options.md b/docs/options.md index 87f7dca50b..7b86ea2803 100644 --- a/docs/options.md +++ b/docs/options.md @@ -348,3 +348,7 @@ with info about your project (name and website) so we can add an entry for you. 1. Pigweed protobuf compiler * Website: https://pigweed.dev/pw_protobuf * Extension: 1155 + +1. Perfetto + * Website: https://perfetto.dev + * Extension: 1156 diff --git a/java/README.md b/java/README.md index 0b56993b36..798ce212f6 100644 --- a/java/README.md +++ b/java/README.md @@ -23,7 +23,7 @@ If you are using Maven, use the following: com.google.protobuf protobuf-java - 3.21.7 + 3.21.8 ``` @@ -37,7 +37,7 @@ protobuf-java-util package: com.google.protobuf protobuf-java-util - 3.21.7 + 3.21.8 ``` @@ -45,7 +45,7 @@ protobuf-java-util package: If you are using Gradle, add the following to your `build.gradle` file's dependencies: ``` - implementation 'com.google.protobuf:protobuf-java:3.21.7' + implementation 'com.google.protobuf:protobuf-java:3.21.8' ``` Again, be sure to check that the version number matches (or is newer than) the version number of protoc that you are using. diff --git a/java/bom/pom.xml b/java/bom/pom.xml index dc655626c3..ebbad006ea 100644 --- a/java/bom/pom.xml +++ b/java/bom/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-bom - 3.21.7 + 3.21.8 pom Protocol Buffers [BOM] 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/pom.xml b/java/core/pom.xml index a6da8c850e..bedb61b915 100644 --- a/java/core/pom.xml +++ b/java/core/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.21.7 + 3.21.8 protobuf-java 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/ByteString.java b/java/core/src/main/java/com/google/protobuf/ByteString.java index 0e03ebd14e..1acbad08b4 100644 --- a/java/core/src/main/java/com/google/protobuf/ByteString.java +++ b/java/core/src/main/java/com/google/protobuf/ByteString.java @@ -75,6 +75,7 @@ import java.util.NoSuchElementException; */ @CheckReturnValue public abstract class ByteString implements Iterable, Serializable { + private static final long serialVersionUID = 1L; /** * When two strings to be concatenated have a combined length shorter than this, we just copy @@ -945,6 +946,8 @@ public abstract class ByteString implements Iterable, Serializable { /** Base class for leaf {@link ByteString}s (i.e. non-ropes). */ abstract static class LeafByteString extends ByteString { + private static final long serialVersionUID = 1L; + @Override protected final int getTreeDepth() { return 0; @@ -1603,7 +1606,6 @@ public abstract class ByteString implements Iterable, Serializable { // Keep this class private to avoid deadlocks in classloading across threads as ByteString's // static initializer loads LiteralByteString and another thread loads BoundedByteString. private static final class BoundedByteString extends LiteralByteString { - private final int bytesOffset; private final int bytesLength; 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/kotlin-lite/pom.xml b/java/kotlin-lite/pom.xml index 60bd0d4a1d..ace12aa6fa 100644 --- a/java/kotlin-lite/pom.xml +++ b/java/kotlin-lite/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.21.7 + 3.21.8 protobuf-kotlin-lite diff --git a/java/kotlin/pom.xml b/java/kotlin/pom.xml index d0f4c2d3ab..27be007720 100644 --- a/java/kotlin/pom.xml +++ b/java/kotlin/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.21.7 + 3.21.8 protobuf-kotlin diff --git a/java/lite.md b/java/lite.md index bd9c5a5bb8..87b917a7bd 100644 --- a/java/lite.md +++ b/java/lite.md @@ -29,7 +29,7 @@ protobuf Java Lite runtime. If you are using Maven, include the following: com.google.protobuf protobuf-javalite - 3.21.7 + 3.21.8 ``` diff --git a/java/lite/pom.xml b/java/lite/pom.xml index a78ff979b3..8075e75efd 100644 --- a/java/lite/pom.xml +++ b/java/lite/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.21.7 + 3.21.8 protobuf-javalite @@ -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/pom.xml b/java/pom.xml index 8b304fa570..ad8628219b 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.21.7 + 3.21.8 pom Protocol Buffers [Parent] diff --git a/java/util/pom.xml b/java/util/pom.xml index 31fcbf269b..1c0ee7b687 100644 --- a/java/util/pom.xml +++ b/java/util/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.21.7 + 3.21.8 protobuf-java-util 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/kokoro/windows/prepare_build_win64.bat b/kokoro/windows/prepare_build_win64.bat index d8eb2a2b30..37d27ac7a7 100644 --- a/kokoro/windows/prepare_build_win64.bat +++ b/kokoro/windows/prepare_build_win64.bat @@ -13,4 +13,4 @@ call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary @rem Convert Windows line breaks to Unix line breaks @rem This allows text-matching tests to pass -find . -type f -print0 | xargs -0 d2u +@find . -type f -print0 | xargs -0 d2u diff --git a/pkg/BUILD.bazel b/pkg/BUILD.bazel index 2d321512d9..b1784f6a67 100644 --- a/pkg/BUILD.bazel +++ b/pkg/BUILD.bazel @@ -6,9 +6,14 @@ load( "pkg_files", "strip_prefix", ) +load("//:protobuf_release.bzl", "package_naming") load(":build_systems.bzl", "gen_file_lists") load(":cc_dist_library.bzl", "cc_dist_library") +package_naming( + name = "protobuf_pkg_naming", +) + pkg_files( name = "wkt_protos_files", srcs = [ diff --git a/protobuf_deps.bzl b/protobuf_deps.bzl index 90a1ed5abc..fb2248a2dd 100644 --- a/protobuf_deps.bzl +++ b/protobuf_deps.bzl @@ -49,9 +49,12 @@ def protobuf_deps(): http_archive( name = "zlib", build_file = "@com_google_protobuf//:third_party/zlib.BUILD", - sha256 = "d8688496ea40fb61787500e863cc63c9afcbc524468cedeb478068924eb54932", - strip_prefix = "zlib-1.2.12", - urls = ["https://github.com/madler/zlib/archive/v1.2.12.tar.gz"], + sha256 = "d14c38e313afc35a9a8760dadf26042f51ea0f5d154b0630a31da0540107fb98", + strip_prefix = "zlib-1.2.13", + urls = [ + "https://github.com/madler/zlib/releases/download/v1.2.13/zlib-1.2.13.tar.xz", + "https://zlib.net/zlib-1.2.13.tar.xz", + ], ) if not native.existing_rule("jsoncpp"): @@ -67,8 +70,8 @@ def protobuf_deps(): _github_archive( name = "utf8_range", repo = "https://github.com/protocolbuffers/utf8_range", - commit = "a67b76f9f40107f2c78a5aa860bb6ce37ed83d85", - sha256 = "de5f99318f3b5073dd99f3d4ca31e00e90a86cc400fb375e2147ae1fd41711ed", + commit = "de0b4a8ff9b5d4c98108bdfe723291a33c52c54f", + sha256 = "5da960e5e5d92394c809629a03af3c7709d2d3d0ca731dacb3a9fb4bf28f7702", ) if not native.existing_rule("rules_cc"): @@ -132,6 +135,6 @@ def protobuf_deps(): _github_archive( name = "upb", repo = "https://github.com/protocolbuffers/upb", - commit = "32c6e9baab03d584b85390fdba789118f20613fc", - #sha256 = "4c82bff4f790dbb5a11ec40b1fac44e7c95d9a63fd215a13aaf44cb27b10ac27", + commit = "9e2d7f02da5440bfb0dfb069f61baa278aa2fbf6", + sha256 = "9eb13368a136af314855e1497838cf3124846b6a73a7e7c882455a52b8c04662", ) diff --git a/protobuf_version.bzl b/protobuf_version.bzl index bf6ec169ac..cc6cf85c55 100644 --- a/protobuf_version.bzl +++ b/protobuf_version.bzl @@ -1,3 +1,3 @@ -PROTOC_VERSION = "21.7" -PROTOBUF_JAVA_VERSION = "3.21.7" -PROTOBUF_PYTHON_VERSION = "4.21.7" +PROTOC_VERSION = "21.8" +PROTOBUF_JAVA_VERSION = "3.21.8" +PROTOBUF_PYTHON_VERSION = "4.21.8" diff --git a/python/google/protobuf/__init__.py b/python/google/protobuf/__init__.py index 70d564a90a..6b0df47af0 100644 --- a/python/google/protobuf/__init__.py +++ b/python/google/protobuf/__init__.py @@ -30,4 +30,4 @@ # Copyright 2007 Google Inc. All Rights Reserved. -__version__ = '4.21.7' +__version__ = '4.21.8' 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/python/google/protobuf/pyext/message.cc b/python/google/protobuf/pyext/message.cc index 532fc3cb4e..f4dd00dabf 100644 --- a/python/google/protobuf/pyext/message.cc +++ b/python/google/protobuf/pyext/message.cc @@ -70,7 +70,6 @@ #include "google/protobuf/pyext/unknown_field_set.h" #include "google/protobuf/pyext/unknown_fields.h" #include "google/protobuf/util/message_differencer.h" -#include "strings/util.h" #include "absl/strings/string_view.h" #include "google/protobuf/io/coded_stream.h" #include "google/protobuf/io/strtod.h" diff --git a/python/setup.py b/python/setup.py index 7a553594a7..9a95ff8f88 100755 --- a/python/setup.py +++ b/python/setup.py @@ -297,6 +297,8 @@ if __name__ == '__main__': extra_objects = ['../bazel-bin/src/google/protobuf/libprotobuf.a'] else: extra_objects = ['../libprotobuf.a'] + extra_objects += list( + glob.iglob('../third_party/utf8_range/*.a')) # Repeat all of these enough times to eliminate order-dependence. extra_objects += list( glob.iglob('../third_party/abseil-cpp/absl/**/*.a')) diff --git a/ruby/ext/google/protobuf_c/message.c b/ruby/ext/google/protobuf_c/message.c index 629513663a..b9de9d9532 100644 --- a/ruby/ext/google/protobuf_c/message.c +++ b/ruby/ext/google/protobuf_c/message.c @@ -1274,7 +1274,9 @@ VALUE build_module_from_enumdesc(VALUE _enumdesc) { int n = upb_EnumDef_ValueCount(e); for (int i = 0; i < n; i++) { const upb_EnumValueDef* ev = upb_EnumDef_Value(e, i); - char* name = strdup(upb_EnumValueDef_Name(ev)); + upb_Arena* arena = upb_Arena_New(); + const char* src_name = upb_EnumValueDef_Name(ev); + char* name = upb_strdup2(src_name, strlen(src_name), arena); int32_t value = upb_EnumValueDef_Number(ev); if (name[0] < 'A' || name[0] > 'Z') { if (name[0] >= 'a' && name[0] <= 'z') { @@ -1287,7 +1289,7 @@ VALUE build_module_from_enumdesc(VALUE _enumdesc) { } } rb_define_const(mod, name, INT2NUM(value)); - free(name); + upb_Arena_Free(arena); } rb_define_singleton_method(mod, "lookup", enum_lookup, 1); 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/compiler/csharp/csharp_map_field.cc b/src/google/protobuf/compiler/csharp/csharp_map_field.cc index efe87f2a6a..50d8b1d828 100644 --- a/src/google/protobuf/compiler/csharp/csharp_map_field.cc +++ b/src/google/protobuf/compiler/csharp/csharp_map_field.cc @@ -88,7 +88,7 @@ void MapFieldGenerator::GenerateMembers(io::Printer* printer) { void MapFieldGenerator::GenerateMergingCode(io::Printer* printer) { printer->Print( variables_, - "$name$_.Add(other.$name$_);\n"); + "$name$_.MergeFrom(other.$name$_);\n"); } void MapFieldGenerator::GenerateParsingCode(io::Printer* printer) { diff --git a/src/google/protobuf/compiler/plugin.pb.h b/src/google/protobuf/compiler/plugin.pb.h index 656ae641e6..802de61516 100644 --- a/src/google/protobuf/compiler/plugin.pb.h +++ b/src/google/protobuf/compiler/plugin.pb.h @@ -15,7 +15,7 @@ #error "your headers." #endif // PROTOBUF_VERSION -#if 3021007 < PROTOBUF_MIN_PROTOC_VERSION +#if 3021008 < PROTOBUF_MIN_PROTOC_VERSION #error "This file was generated by an older version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please" #error "regenerate this file with a newer version of protoc." diff --git a/src/google/protobuf/descriptor.pb.h b/src/google/protobuf/descriptor.pb.h index bd337cbad8..39553f81ce 100644 --- a/src/google/protobuf/descriptor.pb.h +++ b/src/google/protobuf/descriptor.pb.h @@ -15,7 +15,7 @@ #error "your headers." #endif // PROTOBUF_VERSION -#if 3021007 < PROTOBUF_MIN_PROTOC_VERSION +#if 3021008 < PROTOBUF_MIN_PROTOC_VERSION #error "This file was generated by an older version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please" #error "regenerate this file with a newer version of protoc." 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 a2a6c5720c..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)) { @@ -297,23 +297,31 @@ const char* TcParser::MiniParse(PROTOBUF_TC_PARAM_DECL) { &Error, // kSplitMask | FieldKind::kFkMap }; // Just to be sure we got the order right, above. - static_assert(0 == FieldKind::kFkNone); - static_assert(1 == FieldKind::kFkVarint); - static_assert(2 == FieldKind::kFkPackedVarint); - static_assert(3 == FieldKind::kFkFixed); - static_assert(4 == FieldKind::kFkPackedFixed); - static_assert(5 == FieldKind::kFkString); - static_assert(6 == FieldKind::kFkMessage); - static_assert(7 == FieldKind::kFkMap); - - static_assert(8 == (+field_layout::kSplitMask | FieldKind::kFkNone)); - static_assert(9 == (+field_layout::kSplitMask | FieldKind::kFkVarint)); - static_assert(10 == (+field_layout::kSplitMask | FieldKind::kFkPackedVarint)); - static_assert(11 == (+field_layout::kSplitMask | FieldKind::kFkFixed)); - static_assert(12 == (+field_layout::kSplitMask | FieldKind::kFkPackedFixed)); - static_assert(13 == (+field_layout::kSplitMask | FieldKind::kFkString)); - static_assert(14 == (+field_layout::kSplitMask | FieldKind::kFkMessage)); - static_assert(15 == (+field_layout::kSplitMask | FieldKind::kFkMap)); + static_assert(0 == FieldKind::kFkNone, "Invalid table order"); + static_assert(1 == FieldKind::kFkVarint, "Invalid table order"); + static_assert(2 == FieldKind::kFkPackedVarint, "Invalid table order"); + static_assert(3 == FieldKind::kFkFixed, "Invalid table order"); + static_assert(4 == FieldKind::kFkPackedFixed, "Invalid table order"); + static_assert(5 == FieldKind::kFkString, "Invalid table order"); + static_assert(6 == FieldKind::kFkMessage, "Invalid table order"); + static_assert(7 == FieldKind::kFkMap, "Invalid table order"); + + static_assert(8 == (+field_layout::kSplitMask | FieldKind::kFkNone), + "Invalid table order"); + static_assert(9 == (+field_layout::kSplitMask | FieldKind::kFkVarint), + "Invalid table order"); + static_assert(10 == (+field_layout::kSplitMask | FieldKind::kFkPackedVarint), + "Invalid table order"); + static_assert(11 == (+field_layout::kSplitMask | FieldKind::kFkFixed), + "Invalid table order"); + static_assert(12 == (+field_layout::kSplitMask | FieldKind::kFkPackedFixed), + "Invalid table order"); + static_assert(13 == (+field_layout::kSplitMask | FieldKind::kFkString), + "Invalid table order"); + static_assert(14 == (+field_layout::kSplitMask | FieldKind::kFkMessage), + "Invalid table order"); + static_assert(15 == (+field_layout::kSplitMask | FieldKind::kFkMap), + "Invalid table order"); TailCallParseFunc parse_fn = kMiniParseTable[field_type]; PROTOBUF_MUSTTAIL return parse_fn(PROTOBUF_TC_PARAM_PASS); 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