Skip to content

Deprecated field PARSER is accessed in generated code #7271

@adorokhine

Description

@adorokhine

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

Metadata

Metadata

Assignees

Labels

cleanupinactiveDenotes the issue/PR has not seen activity in the last 90 days.java

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions