kidok / protobuf

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

protoc produces java code with compiler errors when terminating message field names with "field" #609

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
1. Use protoc (1.5.0) to generate java code for the following .proto file:
==========================================================================
package example;

message WhateverMessage {
   required string whatever = 110;
}

message ProblemMessage {
   optional WhateverMessage foobar = 120;
   optional WhateverMessage foobar_field = 130;
}
==========================================================================

2. Compile the resulting java code including jars for protobuf-java 1.5.0

I am expecting to get code that compiles, instead I get a compilter error, 
"Duplicate method getFoobarFieldBuilde() in type 
Example.ProblemMessage.Builder".

This is being built with protoc 1.5.0 and corresponding protobuf-java 1.5.0 on 
Red Hat Enterprise Linux 6

The problem appears to be related to having one field ("foobar_field") being 
having another field's name followed by "_field". If I change the name of 
foobar_field to something else, all works fine. The code generation uses a 
scheme that does not guarantee unique method names in this case.

The problem also requires that both fields be a a defined message type. If we 
change one or the other to being a string, the problem will not occur.

Original issue reported on code.google.com by jhaf...@gmail.com on 27 Feb 2014 at 4:44

GoogleCodeExporter commented 9 years ago
Thanks for reporting this. We also have some other similar conflicts, like if 
you name the message field foobar and foobar_or, there will be two 
getFoobarOrBuilder() in the generated code.  It's hard to prevent all these 
conflicts.

Users could avoid it by change the field name, we will not solve this problem.

Thanks

Original comment by jie...@google.com on 18 Jul 2014 at 5:33