-
Notifications
You must be signed in to change notification settings - Fork 15.9k
Closed
Milestone
Description
Here is the excerpt from Descriptors$FieldDescriptor constructor:
private FieldDescriptor(final FieldDescriptorProto proto,
final FileDescriptor file,
final Descriptor parent,
final int index,
final boolean isExtension)
throws DescriptorValidationException {
this.index = index;
this.proto = proto;
fullName = computeFullName(file, parent, proto.getName());
this.file = file;
if (proto.hasType()) {
type = Type.valueOf(proto.getType());
}
if (getNumber() <= 0) {
throw new DescriptorValidationException(this,
"Field numbers must be positive integers.");
}
// Only repeated primitive fields may be packed.
if (proto.getOptions().getPacked() && !isPackable()) {
...
public boolean isPackable() {
return isRepeated() && getLiteType().isPackable();
}
public WireFormat.FieldType getLiteType() {
return table[type.ordinal()];
}
However, if there is an enum or a message proto field with unresolved type (which is okay during cross-linking), then isPackable() will NPE because type ==null in getLiteType() !
This is a serious bug, preventing build of ANY protos with enum or message fields with only the TypeName set. The protoc does its own cross-linking so its Type fields are always set, anything else will fail miserably!
The resolution is simple add type != null in this condition, and if wanted check again after cross-linking:
if ((type != null) && proto.getOptions().getPacked() && !isPackable()) {
Thanks in advance, and hope it will be released soon!
Regards,
David
Metadata
Metadata
Assignees
Labels
No labels