Support JDK 27 end positions (JDK-8372948) - #1786
slachiewicz wants to merge 2 commits into
Conversation
JDK-8372948 removed EndPosTable and JCCompilationUnit.endPositions and re-ordered the four-argument ParserFactory.newParser. Trees now resolves the end-position API once through a method handle and all three call sites go through it; Trees.newParser passes the parser flags in the order each JDK generation expects.
|
Thanks for your interest in palantir/palantir-java-format, @slachiewicz! Before we can accept your pull request, you need to sign our contributor license agreement - just visit https://cla.palantir.com/ and follow the instructions. Once you sign, I'll automatically update this pull request. |
Generate changelog in
|
Before this PR
JDK-8372948 (JDK 27) removed
EndPosTableandJCCompilationUnit.endPositions, soTrees.getEndPosition,StringWrapperandRemoveUnusedImportsfail withNoSuchFieldErroron JDK 27. The same change re-ordered the four-argumentParserFactory.newParser, soFormatterwas passingparseModuleInfo=trueon JDK 27 without noticing. Fixes #1785.After this PR
==COMMIT_MSG==
Support JDK 27 end positions (JDK-8372948)
Treesnow looks up the end-position API once through a method handle:JCTree.getEndPosition()on JDKs withoutEndPosTable, andgetEndPosition(unit.endPositions)via aVarHandleon older ones. All three call sites go through it, andTrees.newParserpasses the parser flags in the order each JDK generation expects. Same approach as google/google-java-format#1328.==COMMIT_MSG==
Verified:
./gradlew :palantir-java-format:check→ 1405 tests pass; the built CLI formats identically on JDK 26 and JDK 27.Possible downsides?
The handle is resolved from class presence, not from the runtime version number, so an early-access build that has one half of JDK-8372948 but not the other would fail at class init instead of at the first formatted file. No such build exists in the released tags.
This change was created with AI assistance.