Skip to content

Build and test on Java 25 with rewrite-java-25 - #1061

Merged
timtebeek merged 1 commit into
mainfrom
tim/migrate-to-java-25
Jul 25, 2026
Merged

Build and test on Java 25 with rewrite-java-25#1061
timtebeek merged 1 commit into
mainfrom
tim/migrate-to-java-25

Conversation

@timtebeek

@timtebeek timtebeek commented Jul 23, 2026

Copy link
Copy Markdown
Member

What

Migrate the build and test suite to a Java 25 toolchain using the rewrite-java-25 parser (replacing rewrite-java-21), mirroring how openrewrite/rewrite-migrate-java does it. This unblocks recipes/tests that rely on Java 22+ language features (e.g. unnamed _ variables).

Changes

  • build.gradle.kts: rewrite-java-21rewrite-java-25, and override the toolchain to 25. The org.openrewrite.build.recipe-library plugin pins the toolchain to 21, so swapping the dependency alone is not enough.
  • .github/workflows/ci.yml: pass java_version: 25 / 21 to the shared ci-gradle.yml, mirroring rewrite-migrate-java, so CI provisions JDK 25 (the toolchain has no auto-download resolver configured).

Fallout fixed

Running the full suite on JDK 25 surfaced exactly three failures, all pre-existing java-21 → java-25 parser attribution differences (no recipe-logic behavior change):

  1. AssertToAssertionsTest.migratesAssertStatementsWithMissingTypeInfo — the java-25 parser leaves assertNotNull(UnknownType.unknownMethod()) unattributed (the erroneous argument prevents overload resolution), so both the type-based matcher and ChangeMethodTargetToStatic miss. Added a fallback in AssertToAssertions that swaps the statically-imported org.junit.Assert.<m> for org.junit.jupiter.api.Assertions.<m> when the call has no method type.
  2. MockitoWhenOnStaticToMockStaticTest.shouldShareSingleMockedStaticForConsecutiveStubbingsOfSameClass — the still-used import static org.mockito.Mockito.mockStatic was dropped (non-compiling). The recipe generates the mockStatic call, so the import is now added unconditionally (onlyIfReferenced=false).
  3. JMockitMockUpToMockitoTest.mockUpMultipleTest — dropped still-used mock / AdditionalAnswers.delegatesTo imports (non-compiling). Root cause: the mocked Foo/Bar were defined as separate sources, so their types weren't on the JavaTemplate parser classpath; java-25 (stricter than java-21) then left the generated mock/mockConstructionWithAnswer/delegatesTo calls unattributed, and the composite's RemoveUnusedImports unfolded the Mockito.* star import and stripped the null-typed imports. The recipe output was already correct — the fix defines Foo/Bar as nested classes (mirroring the passing mockUpStaticMethodTest's MyClazz) so the types resolve. Verified in isolation that java-25 attributes these calls fine for any classpath-resolvable type.

Verification

Full suite green on JDK 25 — 1731 tests, 0 failures.

Follow-up

@github-project-automation github-project-automation Bot moved this to In Progress in OpenRewrite Jul 23, 2026
@timtebeek
timtebeek marked this pull request as draft July 23, 2026 17:37
@timtebeek
timtebeek marked this pull request as ready for review July 24, 2026 22:40
@timtebeek
timtebeek marked this pull request as draft July 24, 2026 22:41
Swap the test parser from `rewrite-java-21` to `rewrite-java-25` and override
the toolchain to 25 (the `recipe-library` plugin pins it to 21), mirroring
rewrite-migrate-java. CI now provisions JDK 25 and 21 via the shared workflow.

The three java-21 -> java-25 fallout failures (AssertToAssertions,
MockitoWhenOnStaticToMockStatic, JMockitMockUpToMockito) were all caused by the
parser dropping a method invocation's type when an argument type was
unresolvable. That is now fixed upstream in openrewrite/rewrite#8318, so no
recipe or test changes are needed here.
@timtebeek
timtebeek force-pushed the tim/migrate-to-java-25 branch from 4172c98 to 8489fcd Compare July 24, 2026 23:37
@timtebeek
timtebeek marked this pull request as ready for review July 25, 2026 07:06
@timtebeek
timtebeek merged commit 4534e08 into main Jul 25, 2026
1 check passed
@timtebeek
timtebeek deleted the tim/migrate-to-java-25 branch July 25, 2026 07:07
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite Jul 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant