Skip to content

DynamicMessage.setField doesn't allow setting value on a repeated enum field! #17

@protobufel

Description

@protobufel

The DynamicMessage.setField has wrong check, preventing setting any ENUM type list on it!
This is a major bug; this has been introduced only in 2.6.0.

Here is the excerpt from the source:

public Builder setField(FieldDescriptor field, Object value) {
  verifyContainingType(field);
  ensureIsMutable();
  if (field.getType() == FieldDescriptor.Type.ENUM) {
    verifyEnumType(field, value);
  }

...
And verifyEnumType doesn't check for repeated value; here it is:

private void verifyEnumType(FieldDescriptor field, Object value) {
  if (value == null) {
    throw new NullPointerException();
  }
  if (!(value instanceof EnumValueDescriptor)) {
    throw new IllegalArgumentException(
      "DynamicMessage should use EnumValueDescriptor to set Enum Value.");
  }

...
If field is repeated, then its value is instanceof List, will never be EnumValueDescriptor!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions