Merge release branch into master. (#7517)

* Added background information about proto3 presence. (#7501)

* Fixed bug in map key sorting for Java TextFormat. (#7508)

Fixes: https://github.com/protocolbuffers/protobuf/issues/7505

* Update protobuf version

* Added a changelog entry about the Java fix. (#7516)
pull/7524/head
Joshua Haberman 5 years ago committed by GitHub
parent 63da77bc97
commit 9952e36f92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGES.txt
  2. 2
      Protobuf-C++.podspec
  3. 2
      Protobuf.podspec
  4. 2
      configure.ac
  5. 2
      csharp/Google.Protobuf.Tools.nuspec
  6. 2
      csharp/src/Google.Protobuf/Google.Protobuf.csproj
  7. 50
      docs/implementing_proto3_presence.md
  8. 2
      java/bom/pom.xml
  9. 2
      java/core/pom.xml
  10. 22
      java/core/src/main/java/com/google/protobuf/TextFormat.java
  11. 21
      java/core/src/test/java/com/google/protobuf/TextFormatTest.java
  12. 2
      java/lite/pom.xml
  13. 2
      java/pom.xml
  14. 2
      java/util/pom.xml
  15. 2
      js/package.json
  16. 24
      php/ext/google/protobuf/package.xml
  17. 2
      php/ext/google/protobuf/protobuf.h
  18. 2
      protoc-artifacts/pom.xml
  19. 2
      python/google/protobuf/__init__.py
  20. 2
      ruby/google-protobuf.gemspec

@ -44,6 +44,7 @@
* Mark java enum _VALUE constants as @Deprecated if the enum field is deprecated * Mark java enum _VALUE constants as @Deprecated if the enum field is deprecated
* reduce <clinit> size for enums with allow_alias set to true. * reduce <clinit> size for enums with allow_alias set to true.
* Sort map fields alphabetically by the field's key when printing textproto. * Sort map fields alphabetically by the field's key when printing textproto.
* Fixed a bug in map sorting that appeared in -rc1 and -rc2 (#7508).
* TextFormat.merge() handles Any as top level type. * TextFormat.merge() handles Any as top level type.
* Throw a descriptive IllegalArgumentException when calling * Throw a descriptive IllegalArgumentException when calling
getValueDescriptor() on enum special value UNRECOGNIZED instead of getValueDescriptor() on enum special value UNRECOGNIZED instead of

@ -1,6 +1,6 @@
Pod::Spec.new do |s| Pod::Spec.new do |s|
s.name = 'Protobuf-C++' s.name = 'Protobuf-C++'
s.version = '3.12.0-rc2' s.version = '3.12.0'
s.summary = 'Protocol Buffers v3 runtime library for C++.' s.summary = 'Protocol Buffers v3 runtime library for C++.'
s.homepage = 'https://github.com/google/protobuf' s.homepage = 'https://github.com/google/protobuf'
s.license = '3-Clause BSD License' s.license = '3-Clause BSD License'

@ -5,7 +5,7 @@
# dependent projects use the :git notation to refer to the library. # dependent projects use the :git notation to refer to the library.
Pod::Spec.new do |s| Pod::Spec.new do |s|
s.name = 'Protobuf' s.name = 'Protobuf'
s.version = '3.12.0-rc2' s.version = '3.12.0'
s.summary = 'Protocol Buffers v.3 runtime library for Objective-C.' s.summary = 'Protocol Buffers v.3 runtime library for Objective-C.'
s.homepage = 'https://github.com/protocolbuffers/protobuf' s.homepage = 'https://github.com/protocolbuffers/protobuf'
s.license = '3-Clause BSD License' s.license = '3-Clause BSD License'

@ -17,7 +17,7 @@ AC_PREREQ(2.59)
# In the SVN trunk, the version should always be the next anticipated release # In the SVN trunk, the version should always be the next anticipated release
# version with the "-pre" suffix. (We used to use "-SNAPSHOT" but this pushed # version with the "-pre" suffix. (We used to use "-SNAPSHOT" but this pushed
# the size of one file name in the dist tarfile over the 99-char limit.) # the size of one file name in the dist tarfile over the 99-char limit.)
AC_INIT([Protocol Buffers],[3.12.0-rc-2],[protobuf@googlegroups.com],[protobuf]) AC_INIT([Protocol Buffers],[3.12.0],[protobuf@googlegroups.com],[protobuf])
AM_MAINTAINER_MODE([enable]) AM_MAINTAINER_MODE([enable])

@ -5,7 +5,7 @@
<title>Google Protocol Buffers tools</title> <title>Google Protocol Buffers tools</title>
<summary>Tools for Protocol Buffers - Google's data interchange format.</summary> <summary>Tools for Protocol Buffers - Google's data interchange format.</summary>
<description>See project site for more info.</description> <description>See project site for more info.</description>
<version>3.12.0-rc2</version> <version>3.12.0</version>
<authors>Google Inc.</authors> <authors>Google Inc.</authors>
<owners>protobuf-packages</owners> <owners>protobuf-packages</owners>
<licenseUrl>https://github.com/protocolbuffers/protobuf/blob/master/LICENSE</licenseUrl> <licenseUrl>https://github.com/protocolbuffers/protobuf/blob/master/LICENSE</licenseUrl>

@ -4,7 +4,7 @@
<Description>C# runtime library for Protocol Buffers - Google's data interchange format.</Description> <Description>C# runtime library for Protocol Buffers - Google's data interchange format.</Description>
<Copyright>Copyright 2015, Google Inc.</Copyright> <Copyright>Copyright 2015, Google Inc.</Copyright>
<AssemblyTitle>Google Protocol Buffers</AssemblyTitle> <AssemblyTitle>Google Protocol Buffers</AssemblyTitle>
<VersionPrefix>3.12.0-rc2</VersionPrefix> <VersionPrefix>3.12.0</VersionPrefix>
<!-- C# 7.2 is required for Span/BufferWriter/ReadOnlySequence --> <!-- C# 7.2 is required for Span/BufferWriter/ReadOnlySequence -->
<LangVersion>7.2</LangVersion> <LangVersion>7.2</LangVersion>
<Authors>Google Inc.</Authors> <Authors>Google Inc.</Authors>

@ -5,6 +5,8 @@ proto3. Proto3 optional fields track presence like in proto2. For background
information about what presence tracking means, please see information about what presence tracking means, please see
[docs/field_presence](field_presence.md). [docs/field_presence](field_presence.md).
## Document Summary
This document is targeted at developers who own or maintain protobuf code This document is targeted at developers who own or maintain protobuf code
generators. All code generators will need to be updated to support proto3 generators. All code generators will need to be updated to support proto3
optional fields. First-party code generators developed by Google are being optional fields. First-party code generators developed by Google are being
@ -14,6 +16,7 @@ independently by their authors. This includes:
- implementations of Protocol Buffers for other languges. - implementations of Protocol Buffers for other languges.
- alternate implementations of Protocol Buffers that target specialized use - alternate implementations of Protocol Buffers that target specialized use
cases. cases.
- RPC code generators that create generated APIs for service calls.
- code generators that implement some utility code on top of protobuf generated - code generators that implement some utility code on top of protobuf generated
classes. classes.
@ -21,6 +24,53 @@ While this document speaks in terms of "code generators", these same principles
apply to implementations that dynamically generate a protocol buffer API "on the apply to implementations that dynamically generate a protocol buffer API "on the
fly", directly from a descriptor, in languages that support this kind of usage. fly", directly from a descriptor, in languages that support this kind of usage.
## Background
Presence tracking was added to proto3 in response to user feedback, both from
inside Google and [from open-source
users](https://github.com/protocolbuffers/protobuf/issues/1606). The [proto3
wrapper
types](https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/wrappers.proto)
were previously the only supported presence mechanism for proto3. Users have
pointed to both efficiency and usability issues with the wrapper types.
Presence in proto3 uses exactly the same syntax and semantics as in proto2.
Proto3 Fields marked `optional` will track presence like proto2, while fields
without any label (known as "singular fields"), will continue to omit presence
information. The `optional` keyword was chosen to minimize differences with
proto2.
Unfortunately, for the current descriptor protos and `Descriptor` API (as of
3.11.4) it is not possible to use the same representation as proto2. Proto3
descriptors already use `LABEL_OPTIONAL` for proto3 singular fields, which do
not track presence. There is a lot of existing code that reflects over proto3
protos and assumes that `LABEL_OPTIONAL` in proto3 means "no presence." Changing
the semantics now would be risky, since old software would likely drop proto3
presence information, which would be a data loss bug.
To minimize this risk we chose a descriptor representation that is semantically
compatible with existing proto3 reflection. Every proto3 optional field is
placed into a one-field `oneof`. We call this a "synthetic" oneof, as it was not
present in the source `.proto` file.
Since oneof fields in proto3 already track presence, existing proto3
reflection-based algorithms should correctly preserve presence for proto3
optional fields with no code changes. For example, the JSON and TextFormat
parsers/serializers in C++ and Java did not require any changes to support
proto3 presence. This is the major benefit of synthetic oneofs.
This design does leave some cruft in descriptors. Synthetic oneofs are a
compatibility measure that we can hopefully clean up in the future. For now
though, it is important to preserve them across different descriptor formats and
APIs. It is never safe to drop synthetic oneofs from a proto schema. Code
generators can (and should) skip synthetic oneofs when generating a user-facing
API or user-facing documentation. But for any schema representation that is
consumed programmatically, it is important to keep the synthetic oneofs around.
In APIs it can be helpful to offer separate accessors that refer to "real"
oneofs (see [API Changes](#api-changes) below). This is a convenient way to omit
synthetic oneofs in code generators.
## Updating a Code Generator ## Updating a Code Generator
When a user adds an `optional` field to proto3, this is internally rewritten as When a user adds an `optional` field to proto3, this is internally rewritten as

@ -4,7 +4,7 @@
<groupId>com.google.protobuf</groupId> <groupId>com.google.protobuf</groupId>
<artifactId>protobuf-bom</artifactId> <artifactId>protobuf-bom</artifactId>
<version>3.12.0-rc-2</version> <version>3.12.0</version>
<packaging>pom</packaging> <packaging>pom</packaging>
<name>Protocol Buffers [BOM]</name> <name>Protocol Buffers [BOM]</name>

@ -4,7 +4,7 @@
<parent> <parent>
<groupId>com.google.protobuf</groupId> <groupId>com.google.protobuf</groupId>
<artifactId>protobuf-parent</artifactId> <artifactId>protobuf-parent</artifactId>
<version>3.12.0-rc-2</version> <version>3.12.0</version>
</parent> </parent>
<artifactId>protobuf-java</artifactId> <artifactId>protobuf-java</artifactId>

@ -490,27 +490,11 @@ public final class TextFormat {
} }
switch (fieldType) { switch (fieldType) {
case BOOLEAN: case BOOLEAN:
boolean aBoolean = (boolean) getKey(); return Boolean.compare((boolean) getKey(), (boolean) b.getKey());
boolean bBoolean = (boolean) b.getKey();
if (aBoolean == bBoolean) {
return 0;
} else if (aBoolean) {
return 1;
} else {
return -1;
}
case LONG: case LONG:
long aLong = (long) getKey(); return Long.compare((long) getKey(), (long) b.getKey());
long bLong = (long) b.getKey();
if (aLong < bLong) {
return -1;
} else if (aLong > bLong) {
return 1;
} else {
return 0;
}
case INT: case INT:
return (int) getKey() - (int) b.getKey(); return Integer.compare((int) getKey(), (int) b.getKey());
case STRING: case STRING:
String aString = (String) getKey(); String aString = (String) getKey();
String bString = (String) b.getKey(); String bString = (String) b.getKey();

@ -1404,6 +1404,27 @@ public class TextFormatTest extends TestCase {
} }
} }
public void testMapDuplicateKeys() throws Exception {
String input =
"int32_to_int32_field: {\n"
+ " key: 1\n"
+ " value: 1\n"
+ "}\n"
+ "int32_to_int32_field: {\n"
+ " key: -2147483647\n"
+ " value: 5\n"
+ "}\n"
+ "int32_to_int32_field: {\n"
+ " key: 1\n"
+ " value: -1\n"
+ "}\n";
TestMap msg = TextFormat.parse(input, TestMap.class);
int val1 = msg.getInt32ToInt32Field().get(1);
TestMap msg2 = TextFormat.parse(msg.toString(), TestMap.class);
int val2 = msg2.getInt32ToInt32Field().get(1);
assertEquals(val1, val2);
}
public void testMapShortForm() throws Exception { public void testMapShortForm() throws Exception {
String text = String text =
"string_to_int32_field [{ key: 'x' value: 10 }, { key: 'y' value: 20 }]\n" "string_to_int32_field [{ key: 'x' value: 10 }, { key: 'y' value: 20 }]\n"

@ -4,7 +4,7 @@
<parent> <parent>
<groupId>com.google.protobuf</groupId> <groupId>com.google.protobuf</groupId>
<artifactId>protobuf-parent</artifactId> <artifactId>protobuf-parent</artifactId>
<version>3.12.0-rc-2</version> <version>3.12.0</version>
</parent> </parent>
<artifactId>protobuf-javalite</artifactId> <artifactId>protobuf-javalite</artifactId>

@ -4,7 +4,7 @@
<groupId>com.google.protobuf</groupId> <groupId>com.google.protobuf</groupId>
<artifactId>protobuf-parent</artifactId> <artifactId>protobuf-parent</artifactId>
<version>3.12.0-rc-2</version> <version>3.12.0</version>
<packaging>pom</packaging> <packaging>pom</packaging>
<name>Protocol Buffers [Parent]</name> <name>Protocol Buffers [Parent]</name>

@ -4,7 +4,7 @@
<parent> <parent>
<groupId>com.google.protobuf</groupId> <groupId>com.google.protobuf</groupId>
<artifactId>protobuf-parent</artifactId> <artifactId>protobuf-parent</artifactId>
<version>3.12.0-rc-2</version> <version>3.12.0</version>
</parent> </parent>
<artifactId>protobuf-java-util</artifactId> <artifactId>protobuf-java-util</artifactId>

@ -1,6 +1,6 @@
{ {
"name": "google-protobuf", "name": "google-protobuf",
"version": "3.12.0-rc.2", "version": "3.12.0",
"description": "Protocol Buffers for JavaScript", "description": "Protocol Buffers for JavaScript",
"main": "google-protobuf.js", "main": "google-protobuf.js",
"files": [ "files": [

@ -10,15 +10,15 @@
<email>protobuf-opensource@google.com</email> <email>protobuf-opensource@google.com</email>
<active>yes</active> <active>yes</active>
</lead> </lead>
<date>2020-05-12</date> <date>2020-05-15</date>
<time>12:48:03</time> <time>13:26:23</time>
<version> <version>
<release>3.12.0RC2</release> <release>3.12.0</release>
<api>3.12.0</api> <api>3.12.0</api>
</version> </version>
<stability> <stability>
<release>beta</release> <release>stable</release>
<api>beta</api> <api>stable</api>
</stability> </stability>
<license uri="https://opensource.org/licenses/BSD-3-Clause">3-Clause BSD License</license> <license uri="https://opensource.org/licenses/BSD-3-Clause">3-Clause BSD License</license>
<notes>GA release.</notes> <notes>GA release.</notes>
@ -557,5 +557,19 @@ G A release.
<license uri="https://opensource.org/licenses/BSD-3-Clause">3-Clause BSD License</license> <license uri="https://opensource.org/licenses/BSD-3-Clause">3-Clause BSD License</license>
<notes>GA release.</notes> <notes>GA release.</notes>
</release> </release>
<release>
<version>
<release>3.12.0</release>
<api>3.12.0</api>
</version>
<stability>
<release>stable</release>
<api>stable</api>
</stability>
<date>2020-05-15</date>
<time>13:26:23</time>
<license uri="https://opensource.org/licenses/BSD-3-Clause">3-Clause BSD License</license>
<notes>GA release.</notes>
</release>
</changelog> </changelog>
</package> </package>

@ -37,7 +37,7 @@
#include "upb.h" #include "upb.h"
#define PHP_PROTOBUF_EXTNAME "protobuf" #define PHP_PROTOBUF_EXTNAME "protobuf"
#define PHP_PROTOBUF_VERSION "3.12.0RC2" #define PHP_PROTOBUF_VERSION "3.12.0"
#define MAX_LENGTH_OF_INT64 20 #define MAX_LENGTH_OF_INT64 20
#define SIZEOF_INT64 8 #define SIZEOF_INT64 8

@ -8,7 +8,7 @@
</parent> </parent>
<groupId>com.google.protobuf</groupId> <groupId>com.google.protobuf</groupId>
<artifactId>protoc</artifactId> <artifactId>protoc</artifactId>
<version>3.12.0-rc-2</version> <version>3.12.0</version>
<packaging>pom</packaging> <packaging>pom</packaging>
<name>Protobuf Compiler</name> <name>Protobuf Compiler</name>
<description> <description>

@ -30,7 +30,7 @@
# Copyright 2007 Google Inc. All Rights Reserved. # Copyright 2007 Google Inc. All Rights Reserved.
__version__ = '3.12.0rc2' __version__ = '3.12.0'
if __name__ != '__main__': if __name__ != '__main__':
try: try:

@ -1,6 +1,6 @@
Gem::Specification.new do |s| Gem::Specification.new do |s|
s.name = "google-protobuf" s.name = "google-protobuf"
s.version = "3.12.0.rc.2" s.version = "3.12.0"
git_tag = "v#{s.version.to_s.sub('.rc.', '-rc')}" # Converts X.Y.Z.rc.N to vX.Y.Z-rcN, used for the git tag git_tag = "v#{s.version.to_s.sub('.rc.', '-rc')}" # Converts X.Y.Z.rc.N to vX.Y.Z-rcN, used for the git tag
s.licenses = ["BSD-3-Clause"] s.licenses = ["BSD-3-Clause"]
s.summary = "Protocol Buffers" s.summary = "Protocol Buffers"

Loading…
Cancel
Save