proto file naming and outer class collisions

3,174 views
Skip to first unread message

bmadigan

unread,
Nov 13, 2008, 1:04:07 PM11/13/08
to Protocol Buffers
I think I'm missing somthing in the style guidelines. If I have a
proto file called "trip_summary.proto", which contains a message
"TripSummary", protoc throws the following error:

-protoc-single:
[exec] --java_out: trip_summary.proto: Cannot generate Java
output because the file's outer class name, "TripSummary", matches the
name of one of the types declared inside it. Please either rename the
type or use the java_outer_classname option to specify a different
outer class name for the .proto file

So, renaming the file to 'trip_summary_protos.proto', protoc generates
2 Java files, one called TripSummaryProtos.java, containing a static
TripSummaryProtos, which contains an inner TripSummary class.
Setting the option 'java_multiple_files=true', I get 2 java files,
with the TripSummary class referencing all of the static members of
TripSummaryProtos. This doesn't cause any problems with using
TripSummary class (that I know of), but why is the container class
necessary?
Should I just define all of my messages in one file and ignore the
outer class in my code?
-bmadigan

bmadigan

unread,
Nov 13, 2008, 1:10:19 PM11/13/08
to Protocol Buffers
I guess it's a good idea to treat the .proto file as a package in java
terms.

Kenton Varda

unread,
Nov 13, 2008, 2:40:39 PM11/13/08
to bmadigan, Protocol Buffers
You're using the java_multiple_files option, I take it?

The outer class is still necessary to store the file's descriptor and any top-level extension definitions.  I suppose the descriptor could be moved into the first class defined in the file but it will take some work and seems like a low priority.  I don't think it ever makes sense to put the extensions inside some other class but not all protos have top-level extensions.

Kenton Varda

unread,
Nov 13, 2008, 2:41:22 PM11/13/08
to bmadigan, Protocol Buffers
BTW, you didn't have to rename your .proto file.  You could have just used the java_outer_classname to make it produce a different class name.

bmadigan

unread,
Nov 13, 2008, 3:33:08 PM11/13/08
to Protocol Buffers
Thanks.
No need to change anything. If it aint broke, don't fix it!
Once I got the extensions mechanism, it all made sense.
-b


On Nov 13, 1:41 pm, Kenton Varda <ken...@google.com> wrote:
> BTW, you didn't have to rename your .proto file. You could have just used
> the java_outer_classname to make it produce a different class name.
>
> On Thu, Nov 13, 2008 at 11:40 AM, Kenton Varda <ken...@google.com> wrote:
> > You're using the java_multiple_files option, I take it?
> > The outer class is still necessary to store the file's descriptor and any
> > top-level extension definitions. I suppose the descriptor could be moved
> > into the first class defined in the file but it will take some work and
> > seems like a low priority. I don't think it ever makes sense to put the
> > extensions inside some other class but not all protos have top-level
> > extensions.
>
Reply all
Reply to author
Forward
0 new messages