protobuf icon indicating copy to clipboard operation
protobuf copied to clipboard

Deprecated field PARSER is accessed in generated code

Open adorokhine opened this issue 5 years ago • 3 comments

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:

  1. Configure gradle to treat warnings as errors:
tasks.withType(JavaCompile) {
  options.compilerArgs << "-Xlint:all" << "-Werror"
}
  1. Try to compile a protobuf
  2. 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

adorokhine avatar Mar 01 '20 19:03 adorokhine

This is still an issue as of 3.19.3.

oehme avatar Jan 28 '22 14:01 oehme

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.

chasebradford avatar Mar 09 '22 00:03 chasebradford

Consider a breaking change in the Java API in a future release to make this static object private.

googleberg avatar Sep 01 '22 18:09 googleberg

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] avatar Mar 27 '24 10:03 github-actions[bot]

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.

github-actions[bot] avatar Apr 11 '24 10:04 github-actions[bot]