Skip to content

Accept an annotated C-style array dimension on a parameter - #65

Merged
abashev merged 1 commit into
mainfrom
parameter-array-dims-annotation
Sep 25, 2026
Merged

abashev merged 1 commit into
mainfrom
parameter-array-dims-annotation

Conversation

@abashev

@abashev abashev commented Sep 24, 2026

Copy link
Copy Markdown
Collaborator

Brings over the fix for google/google-java-format#374, commit google/google-java-format@ed40e472 from google-java-format 1.8.

The bug

A method parameter declared as int a @Anno [] crashed the formatter with a VerifyException from visitAnnotatedArrayType. The parameter's type was printed as a whole, dimensions included, before the name, and the annotated dimension that belongs after the name had nowhere to go. Fields and locals were fine, because their path already splits the dimensions off the type; parameters, try-with-resources and catch parameters go through visitToDeclare, which did not.

From upstream, with the author kept

Checked

  • The golden crashes on main and passes with the change. int @A [] a @B [], var, for (var x : xs) and untyped lambda parameters still format as before.
  • ./gradlew :open-java-format:test on JDK 21: 1501 tests, all green.
  • The 15,747 files of the JDK 21 sources format exactly as before.

A method parameter declared as "int a @anno []" crashed the formatter
with a VerifyException from visitAnnotatedArrayType: the parameter's
type was printed as a whole, dimensions included, before the name, and
the annotated dimension that belongs after the name had nowhere to go.
Fields and locals were fine, because their path already splits the
dimensions off the type; parameters, resources and catch parameters go
through visitToDeclare, which did not.

This ports the fix for google/google-java-format#374, upstream commit
ed40e472 by cushon, together with the null check that
google/google-java-format#463 (upstream commit e19b7637) added next to
it: a "var" declaration or an untyped lambda parameter has no type
tree to split. The golden I374 comes from upstream, with the expected
output in this project's style.

The 15,747 files of the JDK 21 sources format exactly as before.
@abashev
abashev merged commit 30fa1cc into main Sep 25, 2026
15 checks passed
@abashev
abashev deleted the parameter-array-dims-annotation branch September 25, 2026 07:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants