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: overriding getter on a record results in "reference to <getter> is ambiguous #22105

Closed
MorganRoff-UnlikelyAI opened this issue Apr 24, 2024 · 2 comments
Assignees
Labels
team-Rules-Java Issues for Java rules turbine Issues related to https://github.com/google/turbine type: bug untriaged

Comments

@MorganRoff-UnlikelyAI
Copy link

MorganRoff-UnlikelyAI commented Apr 24, 2024

Description of the bug:

This is similar to #17181

According to Oracle's docs (see the section "Explicit Declaration of Record Class Members"), redefining a getter on a Java record should override the default implementation.

For example:

public record Foo(int bar, List<String> baz) {
  /** This should override the default baz() getter. */
  public List<String> baz() {
    return baz == null ? new ArrayList<>() : baz;
  }
}

However, when I try to build this with Bazel, I get error: reference to <getter> is ambiguous. In contrast, the build succeeds as expected with Maven.

My .bazelrc options:
common --java_language_version=17 --java_runtime_version=local_jdk_17 --tool_java_language_version=17 --tool_java_runtime_version=local_jdk_17

I also tried importing the latest java_tools release into my WORKSPACE file to fix this, based on the resolution in
https://github.com/bazelbuild/bazel/issues/17181, but I'm still seeing this error.

Which category does this issue belong to?

Java Rules

What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

Create one java_library with a record that overrides a getter, as demonstrated above.

Create another java_library with a source that tries to use that getter.

Which operating system are you running Bazel on?

ubuntu 22.04.1

What is the output of bazel info release?

release 7.1.1

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

No response

What's the output of git remote get-url origin; git rev-parse HEAD ?

No response

Is this a regression? If yes, please try to identify the Bazel commit where the bug was introduced.

Uncertain, we have not used Bazel to build this code before.

Have you found anything relevant by searching the web?

#17181

Any other information, logs, or outputs that you want to share?

No response

@fmeum
Copy link
Collaborator

fmeum commented Apr 24, 2024

cc @cushon

@cushon cushon self-assigned this Apr 24, 2024
copybara-service bot pushed a commit to google/turbine that referenced this issue Apr 24, 2024
Check if record component getters have been explicitly declared, and don't emit the synthetic methods if they have.

bazelbuild/bazel#22105

PiperOrigin-RevId: 627773759
copybara-service bot pushed a commit to google/turbine that referenced this issue Apr 24, 2024
Check if record component getters have been explicitly declared, and don't emit the synthetic methods if they have.

bazelbuild/bazel#22105

PiperOrigin-RevId: 627802539
@cushon
Copy link
Contributor

cushon commented May 15, 2024

This will be resolved once there's a new java_tools and rules_java release (#22310)

@cushon cushon added the turbine Issues related to https://github.com/google/turbine label May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team-Rules-Java Issues for Java rules turbine Issues related to https://github.com/google/turbine type: bug untriaged
Projects
None yet
Development

No branches or pull requests

7 participants