Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate from Piper for C++, Java, and Python #8224

Merged
merged 15 commits into from Jan 28, 2021
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
810 changes: 0 additions & 810 deletions conformance/failure_list_jruby.txt

This file was deleted.

8 changes: 0 additions & 8 deletions conformance/text_format_failure_list_jruby.txt

This file was deleted.

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