Skip to content

Only collapse the JRE range of the visited method in MinimumJreConditions - #1242

Merged
timtebeek merged 2 commits into
mainfrom
tim/c10-fix
Oct 25, 2026
Merged

timtebeek merged 2 commits into
mainfrom
tim/c10-fix

Conversation

@timtebeek

Copy link
Copy Markdown
Member

When a test's JRE range ended on the minimum version, MinimumJreConditions queued a file-wide ChangeType and attribute edits with doAfterVisit. Every range annotation of that type in the file was rewritten, so with javaVersion 17 @EnabledForJreRange(min = JAVA_21) on another method became @EnabledOnJre(JAVA_17) and enabled that test on a JRE it should skip. The recipe now swaps only the visited method's range annotation for an @EnabledOnJre/@DisabledOnJre built with a typed JavaTemplate. Before, a static JAVA_17 was written untyped and the import static ...JRE.* was dropped. Now it is typed and the import stays.

Two other problems in the same recipe:

  • Filtering @EnabledOnJre({JRE.JAVA_11, JRE.JAVA_17, JRE.JAVA_21}) wrote the JRE constants into the int versions attribute, which failed the recipe run. The recipe now removes the outdated elements from the array where they are, whatever the attribute, and keeps the original formatting. Because of that, two existing expectations now keep { 17, 21 } as written instead of reformatting it to {17, 21}. A bare array left with one element is unwrapped, as assignments already were.
  • Versions that aren't literals, such as @EnabledForJreRange(minVersion = MIN), made Integer.parseInt throw. Those methods are now left alone.

The missing precondition in the issue was already added in #1227.

Verified with ./gradlew test --offline --tests 'org.openrewrite.java.testing.junit6.*': 97 tests, 1 failure. The failure is JUnit5to6MigrationTest.leavesGradleModuleUsingTestNgAlone, a Gradle Tooling API test that couldn't fetch its model locally. On main, all 5 new MinimumJreConditionsTest cases fail.

Fixes item C10 of #1211.

@timtebeek
timtebeek merged commit 2d0906f into main Oct 25, 2026
1 check passed
@timtebeek
timtebeek deleted the tim/c10-fix branch October 25, 2026 22:51
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite Oct 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

1 participant