简体   繁体   中英

Solve override compilation error in protobuf java generated files

I have the following setup:

I have the following dependency in my POM:

<dependency>
    <groupId>com.google.protobuf</groupId>
    <artifactId>protobuf-java</artifactId>
    <version>3.14.0</version>
</dependency>

I have a very simple proto file:

syntax = "proto3";
package com.ziath.genericdecoderserver;
option java_outer_classname = "DecodePackage";

message DecodeData {
    string template = 1;
    bytes image = 2;
    int32 startColumn = 3;
    int32 endColumn = 4;
}

I'm generating the proto file using the version 3.14.0, binary for win64:

PS C:\Users\neilb\Documents\GitHub\GenericDecoderServer\src\main\protobuf\bin> .\protoc.exe --version
libprotoc 3.14.0

This matches the maven dependency I'm pulling in. However the file generated has error with the override annotation:

@java.lang.Override
public com.ziath.genericdecoderserver.DecodePackage.DecodeData buildPartial() {
    com.ziath.genericdecoderserver.DecodePackage.DecodeData result = new 
    com.ziath.genericdecoderserver.DecodePackage.DecodeData(this);
    result.template_ = template_;
    result.image_ = image_;
    result.startColumn_ = startColumn_;
    result.endColumn_ = endColumn_;
    onBuilt();
    return result;
}

The reported error is:

The method buildPartial() of type DecodePackage.DecodeData.Builder must override a superclass method

So this method is in the Builder class which is defined as:

    public static final class Builder extends com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements
        // @@protoc_insertion_point(builder_implements:com.ziath.genericdecoderserver.DecodeData)
    com.ziath.genericdecoderserver.DecodePackage.DecodeDataOrBuilder {

Eclipse is correct the method buildPartial is not in either of the interfaces protobuf is referencing so it looks like a version mismatch but the versions are the same. There are scores of errors in this generated code along the same lines. Does anybody know what the problem is or even seen this before because my searches show nothing from this?

Thanks.

Cheers,

Neil

Solved it. The project was created using Spring Initilaser and for some reason that made the java version to be 1.5 in eclipse. 1.5 does not allow override for interface methods.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM