kidok / protobuf

Automatically exported from code.google.com/p/protobuf
0 stars 0 forks source link

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

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
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.

Original issue reported on code.google.com by jool...@gmail.com on 1 Mar 2011 at 9:22

Attachments:

GoogleCodeExporter commented 9 years ago

Original comment by kenton@google.com on 17 Apr 2011 at 7:47

GoogleCodeExporter commented 9 years ago
this is really annoying, need to add a required field to avoid the warning.

Original comment by wolfma...@gmail.com on 13 Dec 2011 at 8:18

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Is this issue fixed yet?

Original comment by nachaish...@gmail.com on 26 Apr 2013 at 3:32

GoogleCodeExporter commented 9 years ago

Original comment by xiaof...@google.com on 30 Apr 2013 at 1:14

GoogleCodeExporter commented 9 years ago
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?

Original comment by artem.br...@gmail.com on 24 Nov 2013 at 4:22

GoogleCodeExporter commented 9 years ago
Still waiting on a fix for this...

Original comment by Blakeman...@gmail.com on 24 Oct 2014 at 10:05