Issue 545 in protobuf: Unable to set enum field via setField (Java Protobufs 2.5.0)

384 views
Skip to first unread message

prot...@googlecode.com

unread,
Aug 15, 2013, 1:57:39 PM8/15/13
to prot...@googlegroups.com
Status: New
Owner: liu...@google.com
Labels: Type-Defect Priority-Medium

New issue 545 by kylejmci...@gmail.com: Unable to set enum field via
setField (Java Protobufs 2.5.0)
http://code.google.com/p/protobuf/issues/detail?id=545

What steps will reproduce the problem?
1. Compile the attached .proto file to Java
2. Run the attached TestDriver.java file
3. Observe the following exception:

Exception in thread "main" java.lang.IllegalArgumentException: argument
type mismatch
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at
com.google.protobuf.GeneratedMessage.invokeOrDie(GeneratedMessage.java:1427)
at
com.google.protobuf.GeneratedMessage.access$1400(GeneratedMessage.java:57)
at
com.google.protobuf.GeneratedMessage$FieldAccessorTable$SingularEnumFieldAccessor.set(GeneratedMessage.java:1778)
at
com.google.protobuf.GeneratedMessage$Builder.setField(GeneratedMessage.java:366)
at com.sri.scenic.TestDriver.main(TestDriver.java:12)


What is the expected output? What do you see instead?

I expect the field to be set with the legal value Action.Act1. I need to
set the field via setField because in general I may not know the exact type
of message, but I am guaranteed that it will contain a field named "action"
of type Action.


What version of the product are you using? On what operating system?
Java Protobufs 2.5.0 on Windows 7

Thanks for your time.


Attachments:
TestDriver.java 435 bytes
test.proto 241 bytes

--
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,
Aug 15, 2013, 2:13:18 PM8/15/13
to prot...@googlegroups.com

Comment #1 on issue 545 by kylejmci...@gmail.com: Unable to set enum field
via setField (Java Protobufs 2.5.0)
http://code.google.com/p/protobuf/issues/detail?id=545

I should note that I also tried using Action.ACT1_VALUE, as well as a raw
integer as the second argument to setField to no avail.

prot...@googlecode.com

unread,
Aug 15, 2013, 2:16:51 PM8/15/13
to prot...@googlegroups.com

Comment #2 on issue 545 by ibmi...@gmail.com: Unable to set enum field via
Looking at the code for SingularEnumFieldAccessor.set looks like it does

valueOfMethod = getMethodOrDie(type, "valueOf",
EnumValueDescriptor.class);

public void set(final Builder builder, final Object value) {
super.set(builder, invokeOrDie(valueOfMethod, null, value));
}

Which means that you need to be passing it a EnumValueDescriptor instance.

prot...@googlecode.com

unread,
Aug 15, 2013, 2:24:05 PM8/15/13
to prot...@googlegroups.com

Comment #3 on issue 545 by kylejmci...@gmail.com: Unable to set enum field
via setField (Java Protobufs 2.5.0)
http://code.google.com/p/protobuf/issues/detail?id=545

Ah, thanks. I considered that but I think when I tested it I screwed up and
sent in the enum type descriptor rather than the value descriptor. Sorry
for false alarm.

prot...@googlecode.com

unread,
Aug 15, 2013, 5:33:06 PM8/15/13
to prot...@googlegroups.com
Updates:
Status: Invalid

Comment #4 on issue 545 by xiaof...@google.com: Unable to set enum field
via setField (Java Protobufs 2.5.0)
http://code.google.com/p/protobuf/issues/detail?id=545

(No comment was entered for this change.)
Reply all
Reply to author
Forward
0 new messages