2

I have a simple .proto file, from which I generate java classes. The proto file look like this.

message Address {
    string city = 1;
    string country = 2;
}

message PersonalInfo {
    string name = 1;
    repeated Address adresses = 2;
}

The error is:

 error: incompatible types: com.google.protobuf.GeneratedMessageV3.BuilderParent cannot be converted to com.google.protobuf.AbstractMessage.BuilderParent
            getParentForChildren(),
                                ^

I am using 3.1.0 to generate the classes and build the java source. Do I have something misconfigured, Is the proto file incorrect or is it a bug in proto?

safyia
  • 190
  • 2
  • 11
  • 1
    To be clear, this is happening when you try to compile the `.proto` file into Java, not when using the resulting Java class? How are you invoking the Protobuf compiler? – chrylis -cautiouslyoptimistic- Jan 13 '17 at 00:00
  • Thank for the reply. This happens, when I build the java project, the java compilation fails. They are generated from the .proto file just fine. I use `protoc -Ipath_to_protobuf --java_out=path_to_generated_java path_to_protobuf/filename.proto` – safyia Jan 13 '17 at 00:42
  • 1
    Are you sure that your project's Java dependency and the version of `protoc` installed on your system match? – chrylis -cautiouslyoptimistic- Jan 13 '17 at 00:57
  • yes, both are 3.1.0, I tried the protoc HEAD and older maven versions too, with the same result. – safyia Jan 13 '17 at 01:04
  • 1
    https://github.com/bazelbuild/bazel/issues/2106 This issue seems similar to you, and it was resolved by fixing proto. Given limited info and your short proto, my wild guess is... make sure to sync versions of all protoc/lib/include/etc.. and add 'syntax = "proto3";'. – xosp7tom Jan 13 '17 at 11:00
  • I suspect this was a dependency issue. I use an internal library which uses the google cloud java library, which uses an older proto library. When I added the proto library to the build.gradle of my project, it wasn't working correctly. When I added it to the internal library, it did. I am not sure how is determined, which version of the proto library should be used, so I am not even sure why it works now, but it does, thanks. – safyia Jan 16 '17 at 22:11

0 Answers0