Skip to content

Java: NoSuchMethodError on JRE 8 #11393

Description

@minwoox

What version of protobuf and what language are you using?
Version: protobuf-java-3.21.7 (there were no problems with 3.21.1)
Language: Java

What operating system (Linux, Windows, ...) and version?
Linux

What runtime / compiler are you using (e.g., python version or gcc version)
Build JDK 9+ and run with JRE 8

What did you do?
Build Protobuf with JDK 9+ and run with JRE 8.
Because CodedOutputStream uses ByteBuffer.position(int) that overrides the method in the superclass Buffer from JDK9+,
it produces NoSuchMethodError when it's run with JRE 8.
as follow:

    java.lang.NoSuchMethodError: java.nio.ByteBuffer.position(I)Ljava/nio/ByteBuffer;
        at com.google.protobuf.CodedOutputStream$UnsafeDirectNioEncoder.writeStringNoTag(CodedOutputStream.java:2153)
        at com.google.protobuf.CodedOutputStream$UnsafeDirectNioEncoder.writeString(CodedOutputStream.java:1922)
        at com.google.protobuf.GeneratedMessageV3.writeString(GeneratedMessageV3.java:3195)
        at com.linecorp.armeria.grpc.testing.Messages$SimpleResponse.writeTo(Messages.java:4363)
        at com.linecorp.armeria.internal.common.grpc.GrpcMessageMarshaller.serializeProto(GrpcMessageMarshaller.java:202)
        at com.linecorp.armeria.internal.common.grpc.GrpcMessageMarshaller.serializeResponse(GrpcMessageMarshaller.java:145)
        at com.linecorp.armeria.internal.common.grpc.GrpcMessageMarshallerTest.serializeResponse(GrpcMessageMarshallerTest.java:121)

This is a well-described article:
https://www.morling.dev/blog/bytebuffer-and-the-dreaded-nosuchmethoderror/

Please note that there weren't any problems with 3.21.2 version.

What did you expect to see
Just work fine.

What did you see instead?
NoSuchMethodError

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions