Issue 416 in protobuf: HasField is throwing UnsupportedOperationException on repeated fields

712 views
Skip to first unread message

prot...@googlecode.com

unread,
Sep 10, 2012, 9:27:59 AM9/10/12
to prot...@googlegroups.com
Status: New
Owner: liuj...@google.com
Labels: Type-Defect Priority-Medium

New issue 416 by lungu.cr...@gmail.com: HasField is throwing
UnsupportedOperationException on repeated fields
http://code.google.com/p/protobuf/issues/detail?id=416

What steps will reproduce the problem?
1. Use the java bindings.
2. Create a message containing a repeated field.
3. Get the fieldDescriptor of that repeated field.
4. Call hasField(fieldDescriptor) on the message builder.

What is the expected output? What do you see instead?
Expected: true or false, dependind if there is at least one value set for
the repeated field.

Actual: UnsupportedOperationException is thrown.

What version of the product are you using? On what operating system?
Google Protocol Buffers 2.4.1
Ubuntu 12.04 LTS

Please provide any additional information below.
Didn't test on python or C bindings.

prot...@googlecode.com

unread,
Sep 10, 2012, 10:38:02 PM9/10/12
to prot...@googlegroups.com
Updates:
Status: WorkingAsIntended

Comment #1 on issue 416 by jas...@google.com: HasField is throwing
UnsupportedOperationException on repeated fields
http://code.google.com/p/protobuf/issues/detail?id=416

Do you really get an UnsupportedOperationException? You should get
IllegalArgumentException. Docs say that hasField throws exception on
repeated fields:
https://developers.google.com/protocol-buffers/docs/reference/java/com/google/protobuf/MessageOrBuilder.html#hasField(com.google.protobuf.Descriptors.FieldDescriptor)

repeated fields don't have a has accessor, you should call
getRepeatedFieldCount() instead.

Reply all
Reply to author
Forward
0 new messages