Skip to content

require Java 17 and use pattern-matching instanceof in src/main - #126

Merged
pjfanning merged 1 commit into
apache:trunkfrom
pjfanning:java17-idioms
Oct 4, 2026
Merged

pjfanning merged 1 commit into
apache:trunkfrom
pjfanning:java17-idioms

Conversation

@pjfanning

Copy link
Copy Markdown
Member

Moves the baseline from Java 8 to Java 17 and adopts Java 17 language idioms in src/main.

Build

  • build.gradle: source/target 17, default jdkVersion 17; compileJava9 (module-info) also compiles at 17, since a release-9 compile cannot read Java 17 class files; javadoc uses source 17 and links the Java 17 API docs.
  • Removed targetCompatibility = ...14 from the forbiddenApis { } block. It was resolving to the project property and pinning every compile to target 14, which fails with source 17. forbiddenApis now follows the project target.
  • build.xml: release and jdk.version.* set to 17.
  • xkit/README.txt: minimum JDK is now 17.

Code

  • About 150 check-then-cast instanceof sites converted to pattern matching (instanceof Foo foo), mostly via OpenRewrite's InstanceOfPatternMatch, then hand-tidied (binding names, leftover blank lines). Two sites kept their casts where a binding read worse (CharUtil reusing j, Locale assigning chars on both branches).
  • Language features only, no new JDK APIs: the Android API 26 animalsniffer signature check still passes.
  • No text blocks, var, records or switch-statement rewrites in this PR.

Verification

./gradlew check javadoc jar -x rat passes locally on JDK 17 (3194 tests, 0 failures). rat was skipped only because of untracked local IDE directories.

🤖 Generated with Claude Code

Raise the source/target level to Java 17 (Gradle and Ant builds) and
convert check-then-cast instanceof idioms in src/main to Java 17 pattern
matching.

The forbiddenApis block's targetCompatibility line was resolving to the
project property and pinning the whole build to 14, so it is removed;
forbiddenApis now follows the project target.

Only language features are used; no new JDK APIs, so the Android API 26
animalsniffer check still passes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@pjfanning
pjfanning merged commit f0e1fd0 into apache:trunk Oct 4, 2026
3 checks passed
@pjfanning
pjfanning deleted the java17-idioms branch October 4, 2026 13:06
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