fix: retain comments without specialized placements#6813
Open
martinfrancois wants to merge 2 commits into
Open
fix: retain comments without specialized placements#6813martinfrancois wants to merge 2 commits into
martinfrancois wants to merge 2 commits into
Conversation
Spoon issue INRIA#2482's original reproduction was fixed by PR INRIA#2636. This change handles later cases where specialized placement finds no child. Refs INRIA#6812
martinfrancois
force-pushed
the
agent/issue-6812-comment-parent-fallback
branch
from
July 17, 2026 17:17
9426d0b to
a6d8ef6
Compare
martinfrancois
marked this pull request as ready for review
July 17, 2026 18:42
Collaborator
|
@martinfrancois could we keep the log so we get some issues from users? The rest looks good |
Contributor
Author
Sure, done! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Keep comments in the model when a specialized comment-placement visitor cannot attach them to a more specific child node.
Fixes #6812.
Problem
Spoon first tries to attach each source comment to the most specific matching AST node. For some valid comment positions, the specialized placement visitor does not find a child that accepts the comment. Examples include a comment next to an array index or operator and a comment inside a module declaration with no directive. In those cases,
JDTCommentBuilder.javalogged an error and left the comment outside the model.Spoon issue #2482 originally reported comments assigned to the wrong type and a missing end-of-type comment. Spoon PR #2636 fixed that original type-header reproduction by handling comments in declaration modifier ranges. Later comments on #2482 reported the array-access and binary-operator cases covered here. This pull request fixes the remaining path shared by those cases and the annotation and module examples: specialized placement runs, but no child accepts the comment.
This happened while StoneDetector used Spoon and the Eclipse Java compiler (ECJ) to analyze these OpenJDK sources:
WalkerFactory.javacom.foos/module-info.javaNullPointerExceptionTest.javaFdlibmTranslit.javaNumberTest.javaTestGetElementReferenceData.javaapi/mod/module-info.javamVIII/module-info.javaThe eight files produced 21 comment-placement errors.
Change
Tests
CommentTest.java.mvn -q -Dtest=spoon.test.comment.CommentTest,spoon.test.compilation.CompilationTest testpasses: 58 tests, 0 failures, 0 errors.mvn -q -DskipTests verifypasses after restoring the diagnostic.Integration validation
I built the fallback behavior with the combined local ECJ fixes and used the result in StoneDetector.
All eight linked OpenJDK files completed successfully: AST 8/8, CFG 159/159, dominator trees 159/159, and encoded paths 159/159. The run exited with code 0 and the functional result was complete. The current branch intentionally restores the Spoon error diagnostic when fallback placement is used, so equivalent runs retain comments while continuing to report unsupported placements.
Full test suite
The complete Java 25 suite passes 4,462 tests with 0 failures, 0 errors, and 16 skipped.