Skip to content

Commit

Permalink
Merge pull request #8224 from deannagarcia/sync-stage
Browse files Browse the repository at this point in the history
Integrate from Piper for C++, Java, and Python
  • Loading branch information
deannagarcia committed Jan 28, 2021
2 parents 4140735 + 75d125b commit 6969408
Show file tree
Hide file tree
Showing 145 changed files with 3,597 additions and 3,643 deletions.
26 changes: 26 additions & 0 deletions CHANGES.txt
Expand Up @@ -12,17 +12,43 @@ Unreleased Changes (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript)
implementation detail users must not rely on. It should not be used in
unit tests.
* Change the signature of Any::PackFrom() to return false on error.
* Add fast reflection getter API for strings.
* Constant initialize the global message instances
* Avoid potential for missed wakeup in UnknownFieldSet
* Now Proto3 Oneof fields have "has" methods for checking their presence in
C++.
* Bugfix for NVCC
* Return early in _InternalSerialize for empty maps.
* Adding functionality for outputting map key values in proto path logging
output (does not affect comparison logic) and stop printing 'value' in the
path. The modified print functionality is in the
MessageDifferencer::StreamReporter.
* Fixes https://github.com/protocolbuffers/protobuf/issues/8129
* Ensure that null char symbol, package and file names do not result in a
crash.
* Constant initialize the global message instances
* Pretty print 'max' instead of numeric values in reserved ranges.

Java
* Avoid possible UnsupportedOperationException when using CodedInputSteam
with a direct ByteBuffer.
* Make Durations.comparator() and Timestamps.comparator() Serializable.
* Add more detailed error information for dynamic message field type
validation failure
* Removed declarations of functions declared in java_names.h from
java_helpers.h.
* Now Proto3 Oneof fields have "has" methods for checking their presence in
Java.
* Annotates Java proto generated *_FIELD_NUMBER constants.

Python
* Provided an override for the reverse() method that will reverse the internal
collection directly instead of using the other methods of the BaseContainer.
* MessageFactory.CreateProtoype can be overridden to customize class creation.

Javascript
* Generate `getDescriptor` methods with `*` as their `this` type.
* Enforce `let/const` for generated messages.

2020-11-11 version 3.14.0 (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript)

Expand Down
1 change: 1 addition & 0 deletions cmake/libprotoc.cmake
Expand Up @@ -93,6 +93,7 @@ set(libprotoc_headers
${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_message.h
${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_message_field.h
${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_message_layout_helper.h
${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_names.h
${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_options.h
${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_padding_optimizer.h
${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_primitive_field.h
Expand Down
45 changes: 21 additions & 24 deletions java/core/src/main/java/com/google/protobuf/Descriptors.java
Expand Up @@ -190,7 +190,7 @@ public Descriptor findMessageTypeByName(String name) {
name = packageName + '.' + name;
}
final GenericDescriptor result = pool.findSymbol(name);
if (result != null && result instanceof Descriptor && result.getFile() == this) {
if (result instanceof Descriptor && result.getFile() == this) {
return (Descriptor) result;
} else {
return null;
Expand All @@ -214,7 +214,7 @@ public EnumDescriptor findEnumTypeByName(String name) {
name = packageName + '.' + name;
}
final GenericDescriptor result = pool.findSymbol(name);
if (result != null && result instanceof EnumDescriptor && result.getFile() == this) {
if (result instanceof EnumDescriptor && result.getFile() == this) {
return (EnumDescriptor) result;
} else {
return null;
Expand All @@ -238,7 +238,7 @@ public ServiceDescriptor findServiceByName(String name) {
name = packageName + '.' + name;
}
final GenericDescriptor result = pool.findSymbol(name);
if (result != null && result instanceof ServiceDescriptor && result.getFile() == this) {
if (result instanceof ServiceDescriptor && result.getFile() == this) {
return (ServiceDescriptor) result;
} else {
return null;
Expand All @@ -260,7 +260,7 @@ public FieldDescriptor findExtensionByName(String name) {
name = packageName + '.' + name;
}
final GenericDescriptor result = pool.findSymbol(name);
if (result != null && result instanceof FieldDescriptor && result.getFile() == this) {
if (result instanceof FieldDescriptor && result.getFile() == this) {
return (FieldDescriptor) result;
} else {
return null;
Expand Down Expand Up @@ -338,7 +338,7 @@ private static FileDescriptor[] findDescriptors(
final Class<?> descriptorOuterClass,
final String[] dependencyClassNames,
final String[] dependencyFileNames) {
List<FileDescriptor> descriptors = new ArrayList<FileDescriptor>();
List<FileDescriptor> descriptors = new ArrayList<>();
for (int i = 0; i < dependencyClassNames.length; i++) {
try {
Class<?> clazz = descriptorOuterClass.getClassLoader().loadClass(dependencyClassNames[i]);
Expand Down Expand Up @@ -507,11 +507,11 @@ private FileDescriptor(
this.pool = pool;
this.proto = proto;
this.dependencies = dependencies.clone();
HashMap<String, FileDescriptor> nameToFileMap = new HashMap<String, FileDescriptor>();
HashMap<String, FileDescriptor> nameToFileMap = new HashMap<>();
for (FileDescriptor file : dependencies) {
nameToFileMap.put(file.getName(), file);
}
List<FileDescriptor> publicDependencies = new ArrayList<FileDescriptor>();
List<FileDescriptor> publicDependencies = new ArrayList<>();
for (int i = 0; i < proto.getPublicDependencyCount(); i++) {
int index = proto.getPublicDependency(i);
if (index < 0 || index >= proto.getDependencyCount()) {
Expand Down Expand Up @@ -758,7 +758,7 @@ public boolean isReservedName(final String name) {
* y" ranges declared on it.
*/
public boolean isExtendable() {
return proto.getExtensionRangeList().size() != 0;
return !proto.getExtensionRangeList().isEmpty();
}

/**
Expand All @@ -772,7 +772,7 @@ public boolean isExtendable() {
*/
public FieldDescriptor findFieldByName(final String name) {
final GenericDescriptor result = file.pool.findSymbol(fullName + '.' + name);
if (result != null && result instanceof FieldDescriptor) {
if (result instanceof FieldDescriptor) {
return (FieldDescriptor) result;
} else {
return null;
Expand All @@ -797,7 +797,7 @@ public FieldDescriptor findFieldByNumber(final int number) {
*/
public Descriptor findNestedTypeByName(final String name) {
final GenericDescriptor result = file.pool.findSymbol(fullName + '.' + name);
if (result != null && result instanceof Descriptor) {
if (result instanceof Descriptor) {
return (Descriptor) result;
} else {
return null;
Expand All @@ -812,7 +812,7 @@ public Descriptor findNestedTypeByName(final String name) {
*/
public EnumDescriptor findEnumTypeByName(final String name) {
final GenericDescriptor result = file.pool.findSymbol(fullName + '.' + name);
if (result != null && result instanceof EnumDescriptor) {
if (result instanceof EnumDescriptor) {
return (EnumDescriptor) result;
} else {
return null;
Expand Down Expand Up @@ -1701,7 +1701,7 @@ public List<EnumValueDescriptor> getValues() {
*/
public EnumValueDescriptor findValueByName(final String name) {
final GenericDescriptor result = file.pool.findSymbol(fullName + '.' + name);
if (result != null && result instanceof EnumValueDescriptor) {
if (result instanceof EnumValueDescriptor) {
return (EnumValueDescriptor) result;
} else {
return null;
Expand Down Expand Up @@ -1785,7 +1785,7 @@ int getUnknownEnumValueDescriptorCount() {
private final Descriptor containingType;
private EnumValueDescriptor[] values;
private final WeakHashMap<Integer, WeakReference<EnumValueDescriptor>> unknownValues =
new WeakHashMap<Integer, WeakReference<EnumValueDescriptor>>();
new WeakHashMap<>();

private EnumDescriptor(
final EnumDescriptorProto proto,
Expand Down Expand Up @@ -1991,7 +1991,7 @@ public List<MethodDescriptor> getMethods() {
*/
public MethodDescriptor findMethodByName(final String name) {
final GenericDescriptor result = file.pool.findSymbol(fullName + '.' + name);
if (result != null && result instanceof MethodDescriptor) {
if (result instanceof MethodDescriptor) {
return (MethodDescriptor) result;
} else {
return null;
Expand Down Expand Up @@ -2265,12 +2265,12 @@ enum SearchFilter {
}

DescriptorPool(final FileDescriptor[] dependencies, boolean allowUnknownDependencies) {
this.dependencies = new HashSet<FileDescriptor>();
this.dependencies = new HashSet<>();
this.allowUnknownDependencies = allowUnknownDependencies;

for (int i = 0; i < dependencies.length; i++) {
this.dependencies.add(dependencies[i]);
importPublicDependencies(dependencies[i]);
for (Descriptors.FileDescriptor dependency : dependencies) {
this.dependencies.add(dependency);
importPublicDependencies(dependency);
}

for (final FileDescriptor dependency : this.dependencies) {
Expand All @@ -2297,12 +2297,9 @@ private void importPublicDependencies(final FileDescriptor file) {
private final Set<FileDescriptor> dependencies;
private boolean allowUnknownDependencies;

private final Map<String, GenericDescriptor> descriptorsByName =
new HashMap<String, GenericDescriptor>();
private final Map<DescriptorIntPair, FieldDescriptor> fieldsByNumber =
new HashMap<DescriptorIntPair, FieldDescriptor>();
private final Map<DescriptorIntPair, EnumValueDescriptor> enumValuesByNumber =
new HashMap<DescriptorIntPair, EnumValueDescriptor>();
private final Map<String, GenericDescriptor> descriptorsByName = new HashMap<>();
private final Map<DescriptorIntPair, FieldDescriptor> fieldsByNumber = new HashMap<>();
private final Map<DescriptorIntPair, EnumValueDescriptor> enumValuesByNumber = new HashMap<>();

/** Find a generic descriptor by fully-qualified name. */
GenericDescriptor findSymbol(final String fullName) {
Expand Down
Expand Up @@ -266,12 +266,14 @@ void setMemoizedSerializedSize(int size) {
memoizedSerializedSize = size;
}

@Override
public void writeTo(CodedOutputStream output) throws IOException {
Protobuf.getInstance()
.schemaFor(this)
.writeTo(this, CodedOutputStreamWriter.forCodedOutput(output));
}

@Override
public int getSerializedSize() {
if (memoizedSerializedSize == -1) {
memoizedSerializedSize = Protobuf.getInstance().schemaFor(this).getSerializedSize(this);
Expand Down
39 changes: 32 additions & 7 deletions java/core/src/main/java/com/google/protobuf/RawMessageInfo.java
Expand Up @@ -80,14 +80,15 @@ final class RawMessageInfo implements MessageInfo {
* <li>[1]: field type with extra bits:
* <ul>
* <li>v & 0xFF = field type as defined in the FieldType class
* <li>v & 0x100 = is required?
* <li>v & 0x200 = is checkUtf8?
* <li>v & 0x400 = needs isInitialized check?
* <li>v & 0x800 = is map field with proto2 enum value?
* <li>v & 0x0100 = is required?
* <li>v & 0x0200 = is checkUtf8?
* <li>v & 0x0400 = needs isInitialized check?
* <li>v & 0x0800 = is map field with proto2 enum value?
* <li>v & 0x1000 = supports presence checking?
* </ul>
* </ul>
*
* If the file is proto2 and this is a singular field:
* If the (singular) field supports presence checking:
*
* <ul>
* <li>[2]: hasbits offset
Expand Down Expand Up @@ -180,8 +181,32 @@ final class RawMessageInfo implements MessageInfo {
this.defaultInstance = defaultInstance;
this.info = info;
this.objects = objects;
int position = 0;
int value = (int) info.charAt(position++);
int value;
try {
value = (int) info.charAt(0);
} catch (ArrayIndexOutOfBoundsException e) {
// This is a fix for issues
// that error out on a subset of phones on charAt(0) with an index out of bounds exception.
char[] infoChars = info.toCharArray();
info = new String(infoChars);
try {
value = (int) info.charAt(0);
} catch (ArrayIndexOutOfBoundsException e2) {
try {
char[] infoChars2 = new char[info.length()];
info.getChars(0, info.length(), infoChars2, 0);
info = new String(infoChars2);
value = (int) info.charAt(0);
} catch (ArrayIndexOutOfBoundsException e3) {
throw new IllegalStateException(
String.format(
"Failed parsing '%s' with charArray.length of %d", info, infoChars.length),
e3);
}
}
}
int position = 1;

if (value < 0xD800) {
flags = value;
} else {
Expand Down

0 comments on commit 6969408

Please sign in to comment.