Skip to content

Leave a comment that opens with /*** out of javadoc formatting - #74

Merged
abashev merged 1 commit into
mainfrom
javadoc-banner-comments
Sep 25, 2026
Merged

abashev merged 1 commit into
mainfrom
javadoc-banner-comments

Conversation

@abashev

@abashev abashev commented Sep 24, 2026

Copy link
Copy Markdown
Collaborator

Brings over upstream commit google/google-java-format@37171795 (google-java-format 1.8).

The bug

With javadoc formatting on (JavaFormatterOptions.formatJavadoc(true)), a banner such as

/*************************
 * Copyright
 *
 * Some Company
 *************************/

was taken for javadoc because it starts with /**: the row of asterisks moved onto a line of its own, and its paragraphs became <p> tags. The javadoc formatter has nothing to improve in a comment like that.

From upstream, with the author kept

  • google/google-java-format@37171795 by cushon (Liam Miller-Cushon), commit authored by them: a comment whose fourth character is another asterisk is not javadoc. The empty() expectation of JavadocFormattingTest changes with it: /***/ stays as it is.

Added here

  • bannerCommentIsNotJavadoc in JavadocFormattingTest, the banner above with javadoc formatting on.

What changes with javadoc formatting off

The same check decides how blank lines around a comment are treated. A blank line between such a banner and the declaration after it is now kept, as after any other block comment, instead of being removed as it would be after javadoc; a banner with no blank line after it stays as it was.

Checked

  • The new test fails on main and passes with the change.
  • ./gradlew :open-java-format:test on JDK 21: 1498 tests, all green.
  • Of the 15,747 files of the JDK 21 sources, 43 format differently, by 70 blank lines more in all and no other change; every one of them is in the input, after a banner comment. Formatting main's output of those files again with this change adds nothing, apart from the four of them that change on a second run on main already.

With javadoc formatting on, a banner such as

    /*************************
     * Copyright
     *
     * Some Company
     *************************/

was taken for javadoc because it starts with "/**": the row of
asterisks moved onto a line of its own, and its paragraphs became <p>
tags. The javadoc formatter has nothing to improve in a comment like
that.

This ports upstream commit 37171795 by cushon (google-java-format
1.8): a comment whose fourth character is another asterisk is not
javadoc. That holds with javadoc formatting off as well, where it
decides how blank lines around the comment are treated: a blank line
between such a banner and the declaration after it is now kept, as
after any other block comment, instead of being removed as it would be
after javadoc. The empty() expectation changes accordingly, and a test
pins the banner.

Of the 15,747 files of the JDK 21 sources, 43 format differently, by
70 blank lines more in all and no other change; every one of them is
in the input, after a banner comment. The four of those files that
change again on a second run did so on main already.
@abashev
abashev merged commit 7f2a32d into main Sep 25, 2026
15 checks passed
@abashev
abashev deleted the javadoc-banner-comments branch September 25, 2026 08:26
abashev added a commit to openjavaformat/docs that referenced this pull request Sep 25, 2026
…grate

Two more changes on the formatter's main branch move output away from
palantir-java-format 2.98.0, and Migrate lists every such difference.
openjavaformat/open-java-format#76 brings over palantir 2.99.0's one
change: a switch expression that initializes a variable or a field
starts on the declaration's line, 57 declarations in 51 files of the JDK
21 sources. openjavaformat/open-java-format#74 stops counting a comment
that opens with /*** as javadoc, so a blank line between such a banner
and the declaration after it stays: 70 blank lines in 43 files, all of
them in the source. Both join the cast fix as not yet released, and the
corpus paragraph gives their numbers.
abashev added a commit to openjavaformat/docs that referenced this pull request Sep 25, 2026
2.98.0.4 is out on GitHub, Maven Central and the Gradle Plugin Portal,
so the pages now install it. It carries the three output changes that
Migrate listed as not yet in a release: the cast fix
(openjavaformat/open-java-format#78), the switch expression on the
declaration's line (openjavaformat/open-java-format#76) and the /***
banner that no longer counts as javadoc
(openjavaformat/open-java-format#74). Each now says it applies since
2.98.0.4, and the corpus paragraph no longer calls them unreleased.

The GitHub Action page keeps 2.98.0.3 as the default of the action's
version input, because the action itself still defaults to it.
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