Skip to content

Stack overflow (recursive call) in 3.7.0-rc1 (Java) #5657

@maja42

Description

@maja42

What version of protobuf and what language are you using?
Version: 3.7.0-rc1
Language: Java

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

What did you do?
We have protobuf-files that are generated with an older version of the protobuf java compiler, namely protoc-3.5.1-linux-x86_64.
We updated the de Java-Dependency com.google.protobuf from 3.6.1 to 3.7.0-rc1.

What did you see?

The generated code for a protobuf message looks as follows:

public final Builder setUnknownFields(
    final com.google.protobuf.UnknownFieldSet unknownFields) {
    return super.setUnknownFieldsProto3(unknownFields);
}

This calls setUnknownFieldsProto3 in GeneratedMessageV3:

protected BuilderType setUnknownFieldsProto3(UnknownFieldSet unknownFields) {
    return this.setUnknownFields(unknownFields);
}

... which then calls the caller setUnknownFields, producing and endless recursion.

This did not happen with version 3.6.1, but using 3.7.0-rc1 breaks our builds:

java.lang.StackOverflowError
at com.company.app.PbAppProtos$MyMessage$Builder.$jacocoInit(PbAppProtos.java)
at com.company.app.PbAppProtos$MyMessage$Builder.setUnknownFields(PbAppProtos.java)
at com.google.protobuf.GeneratedMessageV3$Builder.setUnknownFieldsProto3(GeneratedMessageV3.java:725)
at com.company.app.PbAppProtos$MyMessage$Builder.setUnknownFields(PbAppProtos.java:12366)
at com.company.app.PbAppProtos$MyMessage$Builder.setUnknownFields(PbAppProtos.java:11585)
at com.google.protobuf.GeneratedMessageV3$Builder.setUnknownFieldsProto3(GeneratedMessageV3.java:725)
at com.company.app.PbAppProtos$MyMessage$Builder.setUnknownFields(PbAppProtos.java:12366)
at com.company.app.PbAppProtos$MyMessage$Builder.setUnknownFields(PbAppProtos.java:11585)
at com.google.protobuf.GeneratedMessageV3$Builder.setUnknownFieldsProto3(GeneratedMessageV3.java:725)
at com.company.app.PbAppProtos$MyMessage$Builder.setUnknownFields(PbAppProtos.java:12366)
at com.company.app.PbAppProtos$MyMessage$Builder.setUnknownFields(PbAppProtos.java:11585)
at com.google.protobuf.GeneratedMessageV3$Builder.setUnknownFieldsProto3(GeneratedMessageV3.java:725)
at com.company.app.PbAppProtos$MyMessage$Builder.setUnknownFields(PbAppProtos.java:12366)
at com.company.app.PbAppProtos$MyMessage$Builder.setUnknownFields(PbAppProtos.java:11585)
...

What did you expect to see

... the new rc should be compatible with older generated protobuf files or have a major version change.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions