protocolbuffers / protobuf

Protocol Buffers - Google's data interchange format
http://protobuf.dev
Other
65.39k stars 15.46k forks source link

java.lang.VerifyError: Bad type on operand stack after migrating #16398

Closed toystorynova closed 2 months ago

toystorynova commented 6 months ago

Migrating my project from 3.26.3 to 4.26.1

What version of protobuf and what language are you using?

C++ - Ubuntu 22.04

5.26.1 libprotoc 26.1

~/Desktop$ protoc --version libprotoc 26.1

Sending protobuf message to:

Java - macOS Java 4.26.1 libprotoc 26.1

Desktop % protoc --version libprotoc 26.1

What operating system (Linux, Windows, ...) and version? Linux - C++ macOS - Java

What runtime / compiler are you using (e.g., python version or gcc version) g++ (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0 CMake?

brew protobuf 26.1

What did you do? Sending a message from C++ to Java that contains a timestamp? causes the following error in Java console

[20:54:55 WARN]: Exception in thread "MessageReceiverThread" java.lang.VerifyError: Bad type on operand stack
[20:54:55 WARN]: Exception Details:
[20:54:55 WARN]:   Location:
[20:54:55 WARN]:     com/toystoryanova/messagecreatr/message/MessageData$Message$Builder.setTime(Lcom/google/protobuf/Timestamp;)Lcom/toystorynova/messagecreatr/message/MessageData$Message$Builder; @32: invokevirtual
[20:54:55 WARN]:   Reason:
[20:54:55 WARN]:     Type 'com/google/protobuf/Timestamp' (current frame, stack[1]) is not assignable to 'com/google/protobuf/GeneratedMessage'
[20:54:55 WARN]:   Current Frame:
[20:54:55 WARN]:     bci: @32
[20:54:55 WARN]:     flags: { }
[20:54:55 WARN]:     locals: { 'com/toystorynova/messagecreatr/message/MessageData$Message$Builder', 'com/google/protobuf/Timestamp' }
[20:54:55 WARN]:     stack: { 'com/google/protobuf/SingleFieldBuilder', 'com/google/protobuf/Timestamp' }
[20:54:55 WARN]:   Bytecode:
[20:54:55 WARN]:     0000000: 2ab4 0126 c700 172b c700 0bbb 01f7 59b7
[20:54:55 WARN]:     0000010: 01f8 bf2a 2bb5 0124 a700 0c2a b401 262b
[20:54:55 WARN]:     0000020: b602 a257 2a59 b400 f511 0400 80b5 00f5
[20:54:55 WARN]:     0000030: 2ab6 0176 2ab0                         
[20:54:55 WARN]:   Stackmap Table:
[20:54:55 WARN]:     same_frame(@19)
[20:54:55 WARN]:     same_frame(@27)
[20:54:55 WARN]:     same_frame(@36)
[20:54:55 WARN]: 
[20:54:55 WARN]:    at messagecreatr.jar//com.toystorynova.messagecreatr.message.MessageData$Message.toBuilder(MessageData.java:7853)
[20:54:55 WARN]:    at messagecreatr.jar//com.toystorynova.messagecreatr.message.MessageData$Message.newBuilder(MessageData.java:7845)
[20:54:55 WARN]:    at messagecreatr.jar//com.toystorynova.messagecreatr.message.MessageData$Message$1.parsePartialFrom(MessageData.java:9896)
[20:54:55 WARN]:    at messagecreatr.jar//com.toystorynova.messagecreatr.message.MessageData$Message$1.parsePartialFrom(MessageData.java:9890)
[20:54:55 WARN]:    at com.google.protobuf.AbstractParser.parsePartialFrom(AbstractParser.java:158)
[20:54:55 WARN]:    at com.google.protobuf.AbstractParser.parseFrom(AbstractParser.java:191)
[20:54:55 WARN]:    at com.google.protobuf.AbstractParser.parseFrom(AbstractParser.java:203)
[20:54:55 WARN]:    at com.google.protobuf.AbstractParser.parseFrom(AbstractParser.java:208)
[20:54:55 WARN]:    at com.google.protobuf.AbstractParser.parseFrom(AbstractParser.java:48)
[20:54:55 WARN]:    at messagecreatr.jar//com.toystorynova.messagecreatr.message.MessageData$Message.parseFrom(MessageData.java:7794)
[20:54:55 WARN]:    at messagecreatr.jar//com.toystorynova.messagecreatr.message.MessageReceiverThread.processStream(MessageReceiverThread.java:63)
[20:54:55 WARN]:    at messagecreatr.jar//com.toystorynova.messagecreatr.message.MessageReceiverThread.run(MessageReceiverThread.java:37)

What did you expect to see It works correctly

What did you see instead? The error above

Anything else we should know about your project / environment I found this following issue (https://github.com/googleapis/google-cloud-java/issues/1239) which led me to believe it was a runtime/compiler mismatch. However, I cannot find anything on either systems that makes me believe that. The two created files that are in the C++ project has Protobuf C++ Version: 5.26.1 in the heading. On the Java side, the generated class has Protobuf Java Version: 4.26.1 in the heading. Both C++/Java are compiled with libprotoc 26.1.

Further verification: Decompiling the Java jar shows the 4.26.1 dependency in the "shaded" package Viewing the CMakeCache.txt on the C++ project shows

//The directory containing a CMake configuration file for Protobuf. Protobuf_DIR:PATH=/usr/local/lib/cmake/protobuf

and running cat protobuf-config-version.cmake in that directory shows set(PACKAGE_VERSION "26.1.0")

and echo'ing Protobuf_VERSION in cmake message(STATUS "Using protobuf version: ${Protobuf_VERSION}") Prints this: Using protobuf version: 26.1.0

Printing the protobuf version inside the program at runtime: std::cout << "Protocol Buffers version: " << GOOGLE_PROTOBUF_VERSION << std::endl; prints Protocol Buffers version: 5026001

shaod2 commented 6 months ago

Probably the Protobuf runtime needs to be updated as well in addition to the Java gencode? Note that we removed GeneratedMessageV3 in the v26.0 release, so that might be what parseFrom expected.

toystorynova commented 6 months ago

Probably the Protobuf runtime needs to be updated as well in addition to the Java gencode? Note that we removed GeneratedMessageV3 in the v26.0 release, so that might be what parseFrom expected.

I believe I have updated the Protobuf runtime on both, though?

CMake points to this on the C++ project side: Protobuf_DIR:PATH=/usr/local/lib/cmake/protobuf

and running cat protobuf-config-version.cmake in that directory shows set(PACKAGE_VERSION "26.1.0")

so that's updated to 26.1.

and on the macOS Java side:

Decompiling the Java jar shows the 4.26.1 dependency in the "shaded" package.

so I'm not sure what else to check

github-actions[bot] commented 3 months ago

We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please add a comment.

This issue is labeled inactive because the last activity was over 90 days ago.

github-actions[bot] commented 2 months ago

We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please reopen it.

This issue was closed and archived because there has been no new activity in the 14 days since the inactive label was added.