Skip to content

Compute tree positions without the SourcePositions methods JDK 27 deprecates - #2257

Merged
wmdietl merged 4 commits into
masterfrom
fix-1637-source-positions
Oct 13, 2026
Merged

wmdietl merged 4 commits into
masterfrom
fix-1637-source-positions

Conversation

@wmdietl

@wmdietl wmdietl commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

Fixes #1637.

JDK 27 deprecates SourcePositions.getStartPosition(CompilationUnitTree, Tree) and getEndPosition(CompilationUnitTree, Tree) for removal. The framework's calls to them carried @SuppressWarnings("removal") with a "TODO: encapsulate methods".

This PR adds TreeUtils.getStartPosition(Tree) and TreeUtils.getEndPosition(CompilationUnitTree, Tree). They compute what javac's JavacTrees implementation of those methods does:

  • start: JCTree.getStartPosition() (that is, TreeInfo.getStartPos).
  • end: JCTree.getEndPosition() on JDKs with JDK-8372948. On earlier JDKs it is JCTree.getEndPosition(root.endPositions). A method handle chooses between the two once, the same way TreePathUtil.getEndPosition in the Annotation File Utilities does. The AFU does not depend on javacutil, so I did not share the code.

The helpers replace the suppressed calls in SourceChecker (-Adetailedmsgtext), BaseTypeVisitor (three sites), and LspTypeInformationPresenter. No test checked the range that -Adetailedmsgtext prints, so a jtreg reference-output test, checker/jtreg/detailedmsgtext/DetailedMsgTextPositions.java, now pins it.

The unused protected fields BaseTypeVisitor.positions and LspTypeInformationReporter.sourcePositions are removed. SuggestedFixData.replaceTree and deleteTree no longer take a SourcePositions argument and use TreeUtils instead; neither method has been in a release.

There is no JDK 27 locally, so the JDK 27/28 CI jobs are what check the new code path.

Locally (JDK 25): assembleForJavac, :framework:test, :javacutil:test, :framework:jtregTests, :checker:jtregTests, :checker:jtregJdk11Tests, spotlessCheck, checkInterning and checkNullness for javacutil and framework.

…recates

JDK 27 deprecates SourcePositions.getStartPosition(CompilationUnitTree,
Tree) and getEndPosition(CompilationUnitTree, Tree) for removal, so the
framework's calls to them carried @SuppressWarnings("removal") with a TODO
to encapsulate them.

Add TreeUtils.getStartPosition(Tree) and
TreeUtils.getEndPosition(CompilationUnitTree, Tree), which compute what
javac's implementation of those methods computes: JCTree.getStartPosition(),
and the end position from the tree, or, before JDK-8372948, from the
compilation unit's end-position table.  Use them in SourceChecker,
BaseTypeVisitor and LspTypeInformationPresenter.  A jtreg test pins the
source range that -Adetailedmsgtext reports, which no test checked.

SuggestedFixData keeps its SourcePositions parameter and its suppressions:
its API takes the SourcePositions to use from the caller.

Fixes #1637.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 12, 2026 01:39

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

wmdietl and others added 3 commits October 13, 2026 03:33
…ameter of SuggestedFixData

BaseTypeVisitor#positions and LspTypeInformationReporter#sourcePositions are
unused.  SuggestedFixData#replaceTree and #deleteTree, which have not been in a
release, locate the tree with TreeUtils instead of a SourcePositions argument.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@wmdietl
wmdietl merged commit 6d14e0d into master Oct 13, 2026
56 checks passed
@wmdietl
wmdietl deleted the fix-1637-source-positions branch October 13, 2026 23: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.

JDK 27: Adapt to sourcePositions.getStartPosition changes in b16

2 participants