Issue 266 in protobuf: Protoc generates unused variable in Java for protobuf with single repeated field

236 views
Skip to first unread message

prot...@googlecode.com

unread,
Mar 1, 2011, 4:23:27 PM3/1/11
to prot...@googlegroups.com
Status: New
Owner: ken...@google.com
Labels: Type-Defect Priority-Medium

New issue 266 by jool...@gmail.com: Protoc generates unused variable in
Java for protobuf with single repeated field
http://code.google.com/p/protobuf/issues/detail?id=266

What steps will reproduce the problem?
1. Create a protobuf definition for a message with a single repeated field
of any type
2. Run protoc on it to generate Java classes

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

The resulting .java source file defines a variable ("int from_bitField0_")
in the message builder's buildPartial method that is never read and thus
causes a compiler warning.

What version of the product are you using? On what operating system?

2.4.0a, on Mac OS X 10.6.6

Please provide any additional information below.

I believe the issue arises because the Repeatable*Field classes in the Java
code generator include the mutability bit in the count of required "builder
bits" for which "local" bit field variables are created, but the
GenerateBuildingCode() method doesn't use it. So if there's only a single
field in a message, and it's repeatable, a local bit field gets created but
never used.

I've attached a patch that modifies GenerateBuildingCode() in the three
field type handler classes to generate code that reads the local bit field.

Attachments:
use_local_bit_builder_for_mutability.diff 3.3 KB

prot...@googlecode.com

unread,
Dec 13, 2011, 3:18:45 PM12/13/11
to prot...@googlegroups.com

Comment #2 on issue 266 by wolfma...@gmail.com: Protoc generates unused
variable in Java for protobuf with single repeated field
http://code.google.com/p/protobuf/issues/detail?id=266

this is really annoying, need to add a required field to avoid the warning.

prot...@googlecode.com

unread,
Jul 11, 2012, 2:02:47 AM7/11/12
to prot...@googlegroups.com

Comment #3 on issue 266 by artem.br...@gmail.com: Protoc generates unused
variable in Java for protobuf with single repeated field
http://code.google.com/p/protobuf/issues/detail?id=266

It is enough to add an optional field to avoid this warning.
But this workaround also is not good.

prot...@googlecode.com

unread,
Apr 25, 2013, 11:32:36 PM4/25/13
to prot...@googlegroups.com

Comment #4 on issue 266 by nachaish...@gmail.com: Protoc generates unused
variable in Java for protobuf with single repeated field
http://code.google.com/p/protobuf/issues/detail?id=266

Is this issue fixed yet?

--
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

mwfong

unread,
Apr 29, 2013, 9:09:31 PM4/29/13
to prot...@googlegroups.com, codesite...@google.com, prot...@googlecode.com
These unused variables are still being generated by protobuf-2.5.0.  Attached is a diff that conditionally suppresses their generation.

protobuf-2.5.0-java_message.cc.diff

prot...@googlecode.com

unread,
Apr 29, 2013, 9:14:23 PM4/29/13
to prot...@googlegroups.com
Updates:
Status: Accepted
Owner: xiaof...@google.com

Comment #5 on issue 266 by xiaof...@google.com: Protoc generates unused
variable in Java for protobuf with single repeated field
http://code.google.com/p/protobuf/issues/detail?id=266

(No comment was entered for this change.)

prot...@googlecode.com

unread,
Nov 24, 2013, 11:23:02 AM11/24/13
to prot...@googlegroups.com

Comment #6 on issue 266 by artem.br...@gmail.com: Protoc generates unused
variable in Java for protobuf with single repeated field
http://code.google.com/p/protobuf/issues/detail?id=266

With last update (2.5.0) added more unused variables for the same *.proto
files in generated *.java.

Are you planning to fix this problem some day?

prot...@googlecode.com

unread,
Oct 24, 2014, 6:06:05 PM10/24/14
to prot...@googlegroups.com

Comment #7 on issue 266 by Blakeman...@gmail.com: Protoc generates unused
variable in Java for protobuf with single repeated field
https://code.google.com/p/protobuf/issues/detail?id=266

Still waiting on a fix for this...
Reply all
Reply to author
Forward
0 new messages