Deprecated field PARSER is accessed in generated code
What version of protobuf and what language are you using? Version: 3.11.4 Language: Java
What operating system (Linux, Windows, ...) and version? Linux 4.15.0-74-generic What runtime / compiler are you using (e.g., python version or gcc version) Java 1.8.0_232
What did you do? Steps to reproduce the behavior:
- Configure gradle to treat warnings as errors:
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:all" << "-Werror"
}
- Try to compile a protobuf
- Build fails on this generated code:
@java.lang.Deprecated public static final com.google.protobuf.Parser<PbStat>
PARSER = new com.google.protobuf.AbstractParser<PbStat>() {
@java.lang.Override
public PbStat parsePartialFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return new PbStat(input, extensionRegistry);
}
};
Error: warning: [deprecation] PARSER in PbStat has been deprecated stat_ = input.readMessage(com.dorokhine.ufs.proto.Inode.PbStat.PARSER, extensionRegistry);
The access to the deprecated field is in the private message constructor, in switch(tag):
case 10: {
com.example.Message.PbStat.Builder subBuilder = null;
if (((bitField0_ & 0x00000002) != 0)) {
subBuilder = stat_.toBuilder();
}
stat_ = input.readMessage(com.example.Message.PbStat.PARSER, extensionRegistry);
if (subBuilder != null) {
subBuilder.mergeFrom(stat_);
stat_ = subBuilder.buildPartial();
}
bitField0_ |= 0x00000002;
break;
}
What did you expect to see Protobuf compiles without warnings
What did you see instead? Build fails
Make sure you include information that can help us debug (full error message, exception listing, stack trace, logs).
Anything else we should know about your project / environment
This is still an issue as of 3.19.3.
This appears to be caused by this change, and is specific to java code generated from syntax2 files. https://github.com/protocolbuffers/protobuf/commit/cc5a1bfede7f5b691760ae3efe271961e466cedb
That change makes the PARSER field deprecated, but generated methods use it anyway, leading to the warning. Perhaps a private method that ignores the deprecation warning could return this field and other generated methods can be changed to reference the non-deprecated method instead.
Consider a breaking change in the Java API in a future release to make this static object private.
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.
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.