aspect-build / aspect-build/rules_lint

[Bug]: When formatting with this rule, Record and other modern Java constructs fail

Open
#134 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
Starlark
Stars
154
Forks
125
Avg merge
3d 21h
Merged PRs (30d)
20

Description

### What happened?

Added a Record file in a java project

When the google java formatter is run directly against the file via a java_binary target, it succeeds

When run via the multi_formatter_binary that consumes that target, we see error: class interface or enum expected

### Version

Development (host) and target OS/architectures: Mac

Output of `bazel --version`: bazel 7.0.2

Version of the Aspect rules, or other relevant rules from your
`WORKSPACE` or `MODULE.bazel` file:
bazel_dep(name = "aspect_rules_lint", version = "0.10.0")
(Also tried 11.0)

Language(s) and/or frameworks involved:
java

### How to reproduce

```shell
java_binary(
name = "java-format",
jvm_flags = [
"--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
"--add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED",
"--add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED",
"--add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",
"--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
],
main_class = "com.google.googlejavaformat.java.Main",
runtime_deps = ["@google-java-format//jar"],
)

multi_formatter_binary(
name = "format",
java = ":java-format",
visibility = ["//visibility:public"],
)

com.my.package

public record MyRecord(String field1, String field2) {

}

running bazel run :java-format -- /path/from/root/to/MyRecord.java, it succeeds without error

running bazel run :format, we receive that error
```

### Any other information?

_No response_

Contributor guide

Open the contributing guide

Research direction

Reproduce the failure with the MyRecord.java example and the shown java_binary and multi_formatter_binary targets. Trace the multi_formatter_binary Java entry point and compare its invocation with the direct java-format command. Done means formatting a Java record through :format succeeds without the “class interface or enum expected” error.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
build-system, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.