bazel icon indicating copy to clipboard operation
bazel copied to clipboard

Bazel fails to build when referencing properties in Java 'record's

Open markvr opened this issue 3 weeks ago • 3 comments

Description of the bug:

Bazel fails to build a Java multi-module project when referencing properties in a Java record between modules.

Build succeeds when using --nojava_header_compilation

Which category does this issue belong to?

No response

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

Create a project with two modules: A and B. Create a record in A:

package org.example.builder;

public record Test() {
    public static final String CONSTANT = "foobar"; 
}

Reference this from a class in B:

package org.example.example.tester;

import org.example.builder.Test;

public class Main {
    public static void main(String[] args) {
        System.out.println(Test.CONSTANT);
    }
}

Build fails:

bazel build //... 
ERROR: /Users/mark.vanrossum/work/temp/jilt-bazel/tester/BUILD.bazel:5:13: Building tester/libtester.jar (1 source file) failed: (Exit 1): java failed: error executing Javac command (from target //tester:tester) external/rules_java++toolchains+remotejdk25_macos_aarch64/bin/java '--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED' '--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED' ... (remaining 19 arguments skipped)
tester/src/main/org/example/tester/Main.java:7: error: cannot find symbol
        System.out.println(Test.CONSTANT);
                               ^
  symbol:   variable CONSTANT
  location: class Test`

Build succeeds with --nojava_header_compilation

 bazel build //... --nojava_header_compilation
WARNING: Build option --java_header_compilation has changed, discarding analysis cache (this can be expensive, see https://bazel.build/advanced/performance/iteration-speed).
INFO: Analyzed 4 targets (0 packages loaded, 4198 targets configured).
INFO: Found 4 targets...
INFO: Elapsed time: 0.318s, Critical Path: 0.14s
INFO: 3 processes: 21 action cache hit, 1 internal, 2 worker.
INFO: Build completed successfully, 3 total actions

Which operating system are you running Bazel on?

MacOS

What is the output of bazel info release?

release 8.5.0rc2

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 ?

fatal: not a git repository (or any of the parent directories): .git

If this is a regression, please try to identify the Bazel commit where the bug was introduced with bazelisk --bisect.

No response

Have you found anything relevant by searching the web?

Can't find anything related.

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

No response

markvr avatar Dec 04 '25 14:12 markvr

Thanks for the report, I had just noticed this, it is a regression after #27810.

I have a fix in progress, and then I will make another turbine release.

@hvadehra unfortunately fixing this will require a follow-up java_tools release, sorry for the trouble :(

cushon avatar Dec 04 '25 15:12 cushon

Amazing quick response thankyou!

markvr avatar Dec 04 '25 16:12 markvr

fixing this will require a follow-up java_tools release

Released in java_tools 18.1 / rules_java 9.3.0

hvadehra avatar Dec 09 '25 15:12 hvadehra

Closing as fixed, please reopen / comment if that's not the case.

hvadehra avatar Dec 17 '25 11:12 hvadehra