Skip to content

Build, test and run the 17 line on JDK 17 - #298

Merged
abashev merged 8 commits into
17.X.Xfrom
abashev/build-on-java-17
Nov 30, 2026
Merged

abashev merged 8 commits into
17.X.Xfrom
abashev/build-on-java-17

Conversation

@abashev

@abashev abashev commented Nov 30, 2026 •

Copy link
Copy Markdown
Collaborator

Before this PR

17.X.X is 21.X.X as it is (#293): it builds on JDK 21, with the IDE plugins, the native image and the WebAssembly module, and a Gradle daemon or a Maven build on JDK 17 cannot load what it makes (class file 65).

After this PR

The 17 line builds, tests and runs on JDK 17 alone. It changes only what JDK 17 cannot build, so that backports from 21.X.X apply as they are.

  • Modules. The formatter, its SPI, jdk-bootstrap and the Gradle plugin. The IDE plugins, the native image, the WebAssembly module and the benchmarks stay in the tree, commented out in settings.gradle, with the two formatterNativeImage blocks that pointed at the native image.
  • Checks. Error Prone, error-prone-support, NullAway and Checkstyle leave the build: their releases are built for Java 21, and the code they would check is checked on 21.X.X. forbidden-apis stays. config/checkstyle stays in the tree.
  • JDK 17. The toolchain, the test JVM, mise.toml and gradle.properties (JDK17_HOME). Every other build plugin loads on JDK 17 as it is. The released gradle-open-java-format:21.0.2 that formats this repository does not, so the branch applies none until 17.1.0 is out; until then, changes made here are formatted with the 21 line's -all.jar.
  • Code. javac 17 has no record or type patterns in switch: BreakBehaviour.Json, two switches in Level and XmlUtils.printInline become instanceof chains. Main shuts its pool down in a finally (ExecutorService is AutoCloseable since 19), and CaseFile uses List.get.
  • Visitor. Java21InputAstVisitor is deleted, and Formatter.visitorFor takes JavaInputAstVisitor on every JDK. The tests for JDK 21 and later stay as they are and skip themselves on 17.
  • A semicolon among the imports. javac 21 rejects a run of them before an import, a record or a module, and javac 17 takes them. ExtraneousSemicolons finds those runs in javac 17's tree and reports them as javac 21 does, among javac's own errors in the order of the file. ExtraneousSemicolonsTest takes every expectation from 21.1.2 on JDK 21, and straySemicolonBetweenImportsReportsTheParseError passes again.
  • A Javadoc reference to an anchor. javac 17 does not parse {@link Set##anchor}, which javadoc reads from JDK 20 on, so the 17 line removed the import of Set that 21.1.2 keeps. RemoveUnusedImports now reads the type from the erroneous tree in {@link}, {@linkplain} and @see, with a case under test-cases-java17/imports.
  • CI. One job, build, on JDK 17; CodeQL and the dependency submission on 17 too. The jdk, native and wasm jobs are gone, and so is mise run ci:native.

Checked on Temurin 17.0.17: ./gradlew check passes (core 1445 tests, Gradle plugin 182, jdk-bootstrap 6), and every class of the four jars is class file 61. The branch's -all.jar on JDK 17 and 21.1.2's on JDK 21 give the same output on 76,612 files, the JDK 17 src.zip (java.base, jdk.compiler) and 400 sources jars from the Gradle cache: diff -rq is empty, and the same 18 files, templates that are no Java, fail on both. mise run ci:lint passes.

Possible downsides?

  • javac 17 warns that CaseTree.getLabels() and CaseLabelTree are a reflective preview API; it is a warning only, three of them.
  • Before a module, the 17 line reports javac 17's own error after the extraneous semicolon, where javac 21 reports the semicolon alone. The first error, and so the message, is the same.
  • mise run ci:build no longer pins a JDK 21 path inside act; I have not run it locally.
  • Until 17.1.0, nothing formats this repository on the branch by itself.

…hmarks out

The 17 line builds what a build on JDK 17 loads: the formatter, its SPI, jdk-bootstrap and the Gradle plugin.
The other modules come with the 21 line. They stay in the tree, commented out in settings.gradle, so that a
backport that touches them applies as it is; the Gradle plugin and jdk-bootstrap no longer ask for the native
image they would test against.
Their releases are built for Java 21 and do not load on JDK 17, and the code they would check is checked on
21.X.X: it comes to the 17 line only as backports. forbidden-apis stays, it runs on JDK 17. config/checkstyle
stays in the tree.
javac 17 has no record patterns and no type patterns in switch: BreakBehaviour.Json, the two switches over
BreakBehaviour in Level and XmlUtils.printInline become instanceof chains that throw in the last branch,
CDATASection still before Text, which it also is. ExecutorService is AutoCloseable since Java 19, so
Main.formatFiles shuts the pool down in a finally, and CaseFile takes List.get for getFirst and getLast.
javac 17 cannot compile Java21InputAstVisitor, which is built on the syntax trees of JDK 21, so the 17 line
deletes it, and Formatter.visitorFor takes JavaInputAstVisitor whatever the JDK. On JDK 21 and later 17.x
formats the syntax of Java 17 through it, as FormatterCasesJava17Test checks on the 21 line; newer syntax needs
21.x. visitorFor keeps its signature, and the tests for JDK 21 and later stay: they do not run on JDK 17, and
backports apply to them as they are.
The toolchain, the test JVM and the JDK that mise installs are 17, and Gradle looks for JDK17_HOME alone. The
released gradle-open-java-format that formats this repository is built for Java 21 and does not load on Gradle
with JDK 17, so the 17 line applies none until 17.1.0 is out; until then, changes made on the branch are
formatted with the 21 line's -all.jar.

Every other build plugin loads on JDK 17 as it is. One test fails here, a semicolon between imports, which javac
17 accepts and javac 21 rejects; the next commit rejects it as javac 21 does.
JLS 7.3 allows no semicolon after the package and import declarations. From Java 21 javac reports a run of
them, at its first, when an import or a declaration that starts with an identifier, a record or a module, comes
after it; javac 17 takes them all. The 17 line finds those runs among the JCSkips of javac 17's tree and reports
them with javac 21's message, line and column, among javac's own errors in the order of the file, so that a file
that 21.x rejects fails on 17.x the same way. Where javac reports them itself, from JDK 21 on, it adds none.

ExtraneousSemicolonsTest takes every expectation from 21.1.2 on JDK 21, through formatSource and
formatSourceAndFixImports, and straySemicolonBetweenImportsReportsTheParseError passes again.
javadoc reads a reference to an anchor of a type, {@link Set##anchor}, from JDK 20 on. javac 21 parses it as a
reference whose qualifier is Set, and RemoveUnusedImports keeps the import of Set; javac 17 keeps the whole tag
as an erroneous tree, so the 17 line took the import for unused and removed it. Found on Guava's
ImmutableCollection, the only file of 76,612 where 17.x on JDK 17 and 21.1.2 on JDK 21 differed.

The 17 line now reads the first name of such a reference from the erroneous tree, in {@link}, {@linkplain} and
@see alike, as visitReference does on JDK 21. The new case under test-cases-java17/imports is 21.1.2's output.
The 17 line builds and tests on JDK 17 alone, so CI has one job, build, on JDK 17, the check the ruleset of
17.X.X requires. The jobs for the newer JDKs, the native image and the WebAssembly module are gone, and so is
mise run ci:native; ci:build no longer pins the path of a JDK 21 in act. CodeQL and the dependency submission
set up JDK 17 too.
@abashev
abashev merged commit 7604bae into 17.X.X Nov 30, 2026
8 checks passed
@abashev
abashev deleted the abashev/build-on-java-17 branch November 30, 2026 20:14
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.

1 participant