Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java: Imported enums from local dependency proto files cannot be used as repeated members #392

Open
loudmouth opened this issue Dec 19, 2024 · 3 comments · May be fixed by #395
Open

Java: Imported enums from local dependency proto files cannot be used as repeated members #392

loudmouth opened this issue Dec 19, 2024 · 3 comments · May be fixed by #395
Labels
bug Something isn't working

Comments

@loudmouth
Copy link

Issue Description

When importing an enum from another protobuf file in the same repo (local dependency) that enum can be used as a member field, but cannot be used as a repeated member field in java_proto_library and java_grpc_library. This issue is reproducible with both versions 5.0.0 and 5.0.1 of rules_proto_grpc_java.

I've pushed a small repo reproducing the issue. This line of code is the source. Changing the usage of the enum to a non-repeated field or commenting it out, the build works, but as a repeated field it fails.

Our project currently is on version 4.4.0 and we are able to build java_proto_library and java_grpc_library with that version when we import enums from dependency protobuf files and use them as repeated members, the targets build succesfully.

Log Output

bazel-out/darwin_x86_64-fastbuild/bin/protobuf/_javac/transactions_java/libtransactions_java_tmp/com/justtechnologies/proto/type/Transaction.java:127: error: cannot find symbol
  private static final com.google.protobuf.Internal.IntListAdapter.IntConverter<
                                                   ^
  symbol:   class IntListAdapter
  location: class Internal
bazel-out/darwin_x86_64-fastbuild/bin/protobuf/_javac/transactions_java/libtransactions_java_tmp/com/justtechnologies/proto/type/Transaction.java:129: error: cannot find symbol
          new com.google.protobuf.Internal.IntListAdapter.IntConverter<
                                          ^
  symbol:   class IntListAdapter
  location: class Internal
bazel-out/darwin_x86_64-fastbuild/bin/protobuf/_javac/transactions_java/libtransactions_java_tmp/com/justtechnologies/proto/type/Transaction.java:142: error: cannot find symbol
    return new com.google.protobuf.Internal.IntListAdapter<
                                           ^
  symbol:   class IntListAdapter
  location: class Internal
bazel-out/darwin_x86_64-fastbuild/bin/protobuf/_javac/transactions_java/libtransactions_java_tmp/com/justtechnologies/proto/type/Transaction.java:847: error: cannot find symbol
      return new com.google.protobuf.Internal.IntListAdapter<
                                             ^
  symbol:   class IntListAdapter
  location: class Internal

rules_proto_grpc Version

5.0.0

Bazel Version

7.4.1

OS

MacOS Sonoma 14.6.1 (23G93)

Link to Demo Repo

https://github.com/justtechnologies/java-grpc-enum

MODULE.bazel or WORKSPACE Content

## MODULE.bazel
bazel_dep(name = "bazel_skylib", version = "1.7.1")
bazel_dep(name = "protobuf", version = "29.2", repo_name = "com_google_protobuf")
bazel_dep(name = "rules_proto", version = "7.1.0")
bazel_dep(name = "rules_proto_grpc_go", version = "5.0.1")
bazel_dep(name = "rules_proto_grpc_java", version = "5.0.0")
bazel_dep(name = "rules_java", version = "8.6.2")
bazel_dep(name = "rules_jvm_external", version = "6.6")
bazel_dep(name = "contrib_rules_jvm", version = "0.27.0")

BUILD Content

load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library")
load("@rules_proto_grpc_java//:defs.bzl", "java_grpc_library", "java_proto_library")

package(default_visibility = ["//visibility:public"])

## Proto Libraries
proto_library(
    name = "commons_proto",
    srcs = ["commons.proto"],
)

proto_library(
    name = "transactions_proto",
    srcs = ["transactions.proto"],
    deps = [
        ":commons_proto",
        "@com_google_protobuf//:duration_proto",
        "@com_google_protobuf//:empty_proto",
        "@com_google_protobuf//:timestamp_proto",
    ],
)

# # Java
java_proto_library(
    name = "commons_java",
    protos = [":commons_proto"],
)

java_grpc_library(
    name = "transactions_java",
    protos = [
        ":commons_proto",
        ":transactions_proto",
    ],
)

Proto Content

commons.proto:


syntax = "proto3";

option java_multiple_files = true;
option java_package = "com.justtechnologies.proto.type";
option java_outer_classname = "CommonsProto";

option go_package = "github.com/justtechnologies/java-gprc-enum/protobuf/commons";

package commons;

// Transaction side.
enum Side {
    SIDE_UNKNOWN = 0;
    SIDE_BUY = 1;
    SIDE_SELL = 2;
}


transactions.proto
```protobuf
syntax = "proto3";

option java_multiple_files = true;
option java_package = "com.justtechnologies.proto.type";
option java_outer_classname = "TransactionsProto";

option go_package = "github.com/justtechnologies/java-gprc-enum/protobuf/transactions";

package transactions;

import "google/protobuf/timestamp.proto";
import "google/protobuf/empty.proto";
import "google/protobuf/duration.proto";
import "protobuf/commons.proto";

service Transactions {
    rpc ListTransactions(google.protobuf.Empty) returns (ListTransactionResponse) {}
}

message ListTransactionResponse {
    repeated Transaction transactions = 1;
}

message Transaction {
    string id = 1;
    google.protobuf.Timestamp timestamp = 2;
    double amount = 3;
    repeated commons.Side side = 4;
}


### Any Other Content

_No response_
@loudmouth loudmouth added the bug Something isn't working label Dec 19, 2024
@loudmouth
Copy link
Author

In an effort to try to discern if this is an issue that should be filed on the protobuf repository, I used the protoc CLI directly and was able to generate both protobuf and grpc outputs with protoc. Invoking protoc at the command line resulted in succesful generation of Java protobuf and gRPC code.

I used protoc version 29.2, which is the same version I have installed via Bazel in the reproduction repo.

gen protobuf

$ protoc --java_out=output/ -I=. protobuf/commons.proto protobuf/transactions.proto

gen grpc

$ protoc --plugin=protoc-gen-grpc-java=/usr/local/bin/protoc-gen-grpc-java \
        --java_out=output/ --grpc-java_out=grpc_output/ \
        -I=. protobuf/commons.proto protobuf/transactions.proto

@loudmouth
Copy link
Author

loudmouth commented Dec 20, 2024

Seems like there have been plenty of fixes for the java protobuf compiler since version 27.1. curious if the fix could be as simple as upgrading to the latest: https://github.com/rules-proto-grpc/rules_proto_grpc/blob/master/MODULE.bazel#L42

Edit: i've tested with protoc version 27.1 at the command line and java outputs are generated correctly so I'm not sure what the issue could be when building through rules_proto_grpc

@loudmouth
Copy link
Author

just learned that this is not just about imported enums, but could also be an enum declared in the same file that it is used.

@loudmouth loudmouth linked a pull request Jan 7, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant