Java generated code fails to compile if 'descriptor' field name is used
#14 392 ouverte le 13 oct. 2023
Métriques du dépôt
- Stars
- (71 223 stars)
- Métriques de merge PR
- (Merge moyen 2j 11h) (185 PRs mergées en 30 j)
Description
What version of protobuf and what language are you using? Version: v24.4 Language: Java
What operating system (Linux, Windows, ...) and version? MacOS 14.0
What runtime / compiler are you using (e.g., python version or gcc version) n/a
What did you do? Steps to reproduce the behavior:
- Create a protobuf message with a field named 'descriptor' (see below).
- Generate code with
protoc com/example/example.proto --java_out=src/main/java. - Compile code (I used a simple Maven project).
syntax = "proto3";
package com.example;
option java_multiple_files = true;
message FailsToCompile {
string descriptor = 1;
}
What did you expect to see Compilation succeeded.
What did you see instead?
[ERROR] COMPILATION ERROR :
[ERROR] src/main/java/com/example/FailsToCompile.java:[50,27] method getDescriptor() is already defined in class com.example.FailsToCompile
[ERROR] src/main/java/com/example/FailsToCompile.java:[412,29] method getDescriptor() is already defined in class com.example.FailsToCompile.Builder
[ERROR] src/main/java/com/example/FailsToCompile.java:[9,14] com.example.FailsToCompile is not abstract and does not override abstract method getDescriptor() in com.example.FailsToCompileOrBuilder
[ERROR] src/main/java/com/example/FailsToCompile.java:[30,7] getDescriptor() in com.example.FailsToCompile cannot implement getDescriptor() in com.example.FailsToCompileOrBuilder
overriding method is static
[ERROR] src/main/java/com/example/FailsToCompile.java:[240,23] com.example.FailsToCompile.Builder is not abstract and does not override abstract method getDescriptor() in com.example.FailsToCompileOrBuilder
[ERROR] src/main/java/com/example/FailsToCompile.java:[245,9] getDescriptor() in com.example.FailsToCompile.Builder cannot implement getDescriptor() in com.example.FailsToCompileOrBuilder
overriding method is static
[ERROR] src/main/java/com/example/FailsToCompile.java:[354,33] cannot find symbol
symbol: method isEmpty()
location: class com.google.protobuf.Descriptors.Descriptor
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.5.1:compile (java-compile) on project example: Compilation failure: Compilation failure:
[ERROR] src/main/java/com/example/FailsToCompile.java:[50,27] method getDescriptor() is already defined in class com.example.FailsToCompile
[ERROR] src/main/java/com/example/FailsToCompile.java:[412,29] method getDescriptor() is already defined in class com.example.FailsToCompile.Builder
[ERROR] src/main/java/com/example/FailsToCompile.java:[9,14] com.example.FailsToCompile is not abstract and does not override abstract method getDescriptor() in com.example.FailsToCompileOrBuilder
[ERROR] src/main/java/com/example/FailsToCompile.java:[30,7] getDescriptor() in com.example.FailsToCompile cannot implement getDescriptor() in com.example.FailsToCompileOrBuilder
[ERROR] overriding method is static
[ERROR] src/main/java/com/example/FailsToCompile.java:[240,23] com.example.FailsToCompile.Builder is not abstract and does not override abstract method getDescriptor() in com.example.FailsToCompileOrBuilder
[ERROR] src/main/java/com/example/FailsToCompile.java:[245,9] getDescriptor() in com.example.FailsToCompile.Builder cannot implement getDescriptor() in com.example.FailsToCompileOrBuilder
[ERROR] overriding method is static
[ERROR] src/main/java/com/example/FailsToCompile.java:[354,33] cannot find symbol
[ERROR] symbol: method isEmpty()
[ERROR] location: class com.google.protobuf.Descriptors.Descriptor
[ERROR] -> [Help 1]
Perhaps https://github.com/protocolbuffers/protobuf/blob/7789b3ac85248ad75631a1919071fa268e466210/src/google/protobuf/compiler/java/names.cc#L83-L99 needs to be updated to add Descriptor to the list of forbidden names?