protobuf的2.5.0错误?错误、protobuf

2023-09-08 09:32:42 作者:养猪仙

我已经从谷歌protobuf的v迁移。2.4.1到v。2.5.0(无其他变动)。

I've migrated from google protobuf v. 2.4.1 to v. 2.5.0 (no other change).

我有一个完全运行的客户端 - 服务器[机器人<> GAE开发服务器]使用2.4.1通信。 现在,随着2.5.0断裂。

I had a perfectly working client-server [android<>gae dev server] communication using 2.4.1. Now with 2.5.0 it is broken.

在没有任何修改的.proto文件,我设置我的客户端和服务器与新的2.5.0罐,并用新的protoc可执行我已经生成的客户端和服务器从同一原始一个新的源文件文件。

Without any modification to the .proto file, I've setup my client and server with the new 2.5.0 jar, and with the new protoc executable I've generated a new source file for client and server from the same proto file.

现在我得到这个错误,当我试图解析邮件的服务器上:

Now I get this error on the server when I'm trying to parse the message:

VerifyError: class ... overrides final method getUnknownFields.()Lcom/google/protobuf/UnknownFieldSet;

完整的堆栈:

full stack:

java.lang.VerifyError: class com.mta.pb.ACM$MyRequest overrides final method getUnknownFields.()Lcom/google/protobuf/UnknownFieldSet;
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at com.google.appengine.tools.development.IsolatedAppClassLoader.loadClass(IsolatedAppClassLoader.java:213)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:186)
at com.google.appengine.tools.development.agent.runtime.RuntimeHelper.checkRestricted(RuntimeHelper.java:70)
at com.google.appengine.tools.development.agent.runtime.Runtime.checkRestricted(Runtime.java:64)
**at com.mta.server.p.AndroidServletP.doPost(AndroidServletP.java:91)** <- my code
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
at com.googlecode.objectify.cache.AsyncCacheFilter.doFilter(AsyncCacheFilter.java:57)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.api.socket.dev.DevSocketFilter.doFilter(DevSocketFilter.java:74)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    ...etc

我已经尝试过

东西:

Things I've already tried:

1)读的changelog,我试图从改变解析code:

1) Reading the changelog, I've tried to change the parse code from:

            request = MyRequest.parseFrom(requstBlob); 

            request = MyRequest.PARSER.parseFrom(requstBlob); 

(这是在同一行91,你在堆栈跟踪中看到的)。 它并没有改变任何事情。同样的错误。

(this is the same line 91 that you see in the stack trace). It didn't change a thing. Same error.

2)我试图手动解析消息: 我打印出的base64字符串来服务器,将其转换成二进制

2) I've tried to parse the message manually: I printed out the base64 string coming to the server, converted it into binary

base64 -d in64 > out64.bin

protoc --decode=MyRequest my.proto < out64.bin > tmp.txt

和它解析它完美。 所以这个问题是只在新的protobuf的解析部分

And it parses it perfectly. So the problem is only at the parsing part of the new protobuf.

3)我试着服用ReqType出MyRequest,没有效果的。

3) I've tried taking ReqType out of MyRequest, no effect.

有关参考:相关的protobuf定义

For reference: the relevant protobuf definition

/**
 * Master request object
 */
message MyRequest {
    optional RequestContext context = 1;
    optional MyReport myReport = 2;
    optional CategoryRequest catRequest = 3;
    optional GetMessage getMessage = 4;
    optional SearchRequest searchRequest = 5;
    enum ReqType {
        UNDEFINED = 1;
        REGISTER = 104;
        UPDATE = 123;
        GET_PAYLOAD = 100;
        SEARCH = 200;
        REPEAT_GCM = 623;
        REPEAT_PREPARE = 842;
    }
    optional ReqType reqType = 10;
    optional bool repeat = 11;
}

任何意见将大大AP preciated!

Any advice will be greatly appreciated!

推荐答案

我会想你没升级/重新编译的东西。在protobuf的2.4.1版本诠释的罐子。

I would guess you did not upgrade / recompile something. In protobuf 2.4.1 version int the jars.

在 GeneratedMessage 类, getUnknownFields 是最后的方法2.4.1但2.5.0它变成了:

in the GeneratedMessage class, getUnknownFields was a final method in 2.4.1 but in 2.5.0 it becomes:

  //@Override (Java 1.6 override semantics, but we must support 1.5)
  public UnknownFieldSet getUnknownFields() {
    throw new UnsupportedOperationException(
        "This is supposed to be overridden by subclasses.");
  }

和在生成的类中重写。您可能需要重新编译使用生成的协议缓冲区类所有的类。

and is overridden in the generated class. You may need to recompile all your classes that use generated protocol buffer classes.

由于消息

java.lang.VerifyError: class com.mta.pb.ACM$MyRequest overrides final method getUnknownFields.()Lcom/google/protobuf/UnknownFieldSet;

这告诉你,你正在运行code 生成与协议2.5.0缓冲带的协议fuffers-2.4.1(或更早)的容器。

This tells you you are running code generated with Protocol-Buffers 2.5.0 with a protocol-fuffers-2.4.1 (or earlier) jar.

 
精彩推荐
图片推荐