Issue 506 in protobuf: Java DynamicMessage.Builder#getField doesn't return empty list for unset repeated Message fields, but a default Message instead.

37 views
Skip to first unread message

prot...@googlecode.com

unread,
Apr 26, 2013, 10:25:23 PM4/26/13
to prot...@googlegroups.com
Status: New
Owner: liu...@google.com
Labels: Type-Defect Priority-Medium

New issue 506 by dav.co...@gmail.com: Java DynamicMessage.Builder#getField
doesn't return empty list for unset repeated Message fields, but a default
Message instead.
http://code.google.com/p/protobuf/issues/detail?id=506

What steps will reproduce the problem?
1. for any unset repeated Message field
2. call DynamicMessage.Builder#getField
3. returns the default Message (wrong!)

What is the expected output? What do you see instead?
Should return an empty list!

What version of the product are you using? On what operating system?
Java, protobuf 2.5

Please provide any additional information below.

The fix is easy:

instead of:
...
if (result == null) {
if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
result = getDefaultInstance(field.getMessageType());
...

write:
...
if (result == null) {
if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
if (field.isRepeated()) {
result = Collections.emptyList();
} else {
result = getDefaultInstance(field.getMessageType());
}
...




--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

prot...@googlecode.com

unread,
Apr 27, 2013, 3:52:09 AM4/27/13
to prot...@googlegroups.com
Updates:
Status: Accepted
Owner: xiaof...@google.com

Comment #1 on issue 506 by xiaof...@google.com: Java
DynamicMessage.Builder#getField doesn't return empty list for unset
repeated Message fields, but a default Message instead.
http://code.google.com/p/protobuf/issues/detail?id=506

(No comment was entered for this change.)

prot...@googlecode.com

unread,
Jul 21, 2014, 1:15:08 AM7/21/14
to prot...@googlegroups.com
Updates:
Status: Started
Owner: jie...@google.com
Labels: FixedIn-2.6.0

Comment #2 on issue 506 by jie...@google.com: Java

prot...@googlecode.com

unread,
Aug 25, 2014, 11:19:31 PM8/25/14
to prot...@googlegroups.com
Updates:
Status: Fixed

Comment #3 on issue 506 by jie...@google.com: Java
DynamicMessage.Builder#getField doesn't return empty list for unset
repeated Message fields, but a default Message instead.
https://code.google.com/p/protobuf/issues/detail?id=506
Reply all
Reply to author
Forward
0 new messages