1

I am trying to build some preexisting Java code which includes google protocol buffers in its transport layer. The plugin I am using I have included in my pom file with the following element:

<plugin>
    <groupId>com.github.igor-petruk.protobuf</groupId>
    <artifactId>protobuf-maven-plugin</artifactId>
    <version>0.6.3</version>
    <executions>
        <execution>
            <goals>
                <goal>run</goal>
            </goals>
        </execution>
    </executions>
</plugin>

I have installed protobuf version 2.4.1 and protoc is available over the command line, and the version of protobuf-java I am including in my pom is also 2.4.1 from the com.google.protobuf group. I must use this tech stack as I am working with an existing codebase as I previously mentioned, but despite the fact that there is a newer version of protobufs out this is not the problem I am experiencing.

The problem is that the generated code from the protoc binary (invoked by the above mentioned maven plugin) does not implement an abstract function from a parent class defined in the protobuf library imported into my project from maven. Here is the error:

[ERROR] <generated java class from protoc> is not abstract and does not override abstract method getParserForType() in com.google.protobuf.MessageLite

My assumption is that there is some configuration error with the protobuf library, and that this function getParserForType exists in one of the libraries but not the other.

Charlie
  • 11
  • 3
  • You have to Generate the Java code with the same version of protoc as the library you plan to run it against !!. In this question http://stackoverflow.com/questions/15908268/error-with-serialization-with-protobuf/15913425#15913425 there is a different version mismatch (and different error) but the getParserForType() method can cause the problem – Bruce Martin Oct 17 '13 at 21:48
  • Thanks for your reply, but my library versions seem to be appropriately configured. At this point in time I believe this issue has something to do with my mistake of originally installing protobuf version 2.5.0 and then attempting to uninstall it and downgrade to 2.4.1 and I do not know the exact solution here. – Charlie Nov 19 '13 at 23:28
  • To me, It sounds like the Generated-Java code was generated with 2.5.0 but you are running the 2.4.1 libraries – Bruce Martin Nov 20 '13 at 01:16
  • In other words check the protoc you used to generate the java classes !!!. protoc accepts --version option. If it is 2.4.1 regenerate your java classes – Bruce Martin Nov 20 '13 at 01:21
  • Yes I frequently regenerate my java classes as this happens when running mvn. One of the behaviors of the [protobuf plugin](https://github.com/igor-petruk/protobuf-maven-plugin) is that it checks the version of protobufs you are using in your project against the version of protoc installed on your system, and mine are both 2.4.1 as expected. It was some time ago that I installed the protoc binary and libraries but I believe I did it with homebrew. This issue is an environment configuration issue but as I said everything appears to be configured correctly. – Charlie Nov 20 '13 at 01:41
  • Now I am very confused. I changed my protobuf dependency to 2.5.0 and it is compiling successfully. This may cause problems with coworkers in the future but for now I can build again. Thank you for your help. – Charlie Nov 20 '13 at 02:18
  • As I stated, I think the Generated Java class's where generated by 2.5.0. There may be a 2.5.0 protoc.exe some where on the path. I will do a summary answer in case other people have the same issue. – Bruce Martin Nov 20 '13 at 02:34

1 Answers1

1

This sounds like a mis-match between the Generated java code and the protobuf jar library. In particular I think the java code was generated with protoc 2.5.0 and you are running an earlier version (2.4.1) of the protobuf jar.

you can check the version of protoc in use by

protoc --version

If it is 2.5.0 generate and re-install protoc version 2.4.1

If you have 2.4.1

  • Re-generate the java classes (manually ?)
  • compare with the current classes

Alternaitely try using the 2.5.0 version of the protobuf jar.

note: For most versions of protocol buffers it is not critical that the protoc version used to generate the java class is the same as the jar library. In protbuf 2.5.0 a lot of methods where moved from the base classes int the jar library to the generated code.

Bruce Martin
  • 10,358
  • 1
  • 27
  • 38