Handle extra semicolons after import statements#6323
Closed
saranshflip wants to merge 9 commits intoopenrewrite:mainfrom
Closed
Handle extra semicolons after import statements#6323saranshflip wants to merge 9 commits intoopenrewrite:mainfrom
saranshflip wants to merge 9 commits intoopenrewrite:mainfrom
Conversation
Enhanced the parser to detect and consume extra semicolons following import statements, storing them in the whitespace for accurate source representation. Added a debug test to verify import parsing and whitespace handling.
Refine comment for clarity in parsing success case.
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
timtebeek
reviewed
Jan 7, 2026
| case ASSIGNMENT: | ||
| case DO_WHILE_LOOP: | ||
| case IMPORT: | ||
| case IMPORT:{ |
Member
There was a problem hiding this comment.
Given the fall through from above this should probably become it's only block below THROW.
timtebeek
reviewed
Jan 7, 2026
Comment on lines
+2023
to
+2028
| System.err.println("IMPORT: consumed " + extraSemicolons + " extra semicolon(s), cursor now at " + cursor); | ||
| } | ||
|
|
||
|
|
||
| System.err.println("IMPORT: cursor after=" + cursor + ", char='" + | ||
| (cursor < source.length() ? source.charAt(cursor) : "EOF") + "'"); |
Member
There was a problem hiding this comment.
Let's move these prints into spec.afterRecipe in the unit test, and not here in the parser.
Member
|
We've since seen this parallel alternative fix go in Thanks again! |
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.
What's changed?
Added debug test to investigate Java parser behavior with consecutive semicolons in import statements. Enhanced parser to detect and consume extra semicolons following import statements, storing them in the whitespace for accurate source representation.
What's your motivation?
Investigating a parsing issue where consecutive semicolons in import statements (e.g., import java.util.*;;) cause parser failures or generate incorrect LST with J.Erroneous nodes. This test helps identify the root cause and validates potential fixes.
Anything in particular you'd like reviewers to focus on?
Current Status: The parser now bypasses the parsing error and generates an LST tree, but the tree contains J.Erroneous nodes which indicates the fix is incomplete.
Key concerns:
Would appreciate feedback on:
Anyone you would like to review specifically?
Looking for maintainers familiar with the Java parser implementation and LST tree generation.
Have you considered any alternatives or workarounds?
Any additional context
This is a work-in-progress contribution. The debug test successfully identifies the issue and the current fix prevents parse failures, but the LST generation needs refinement. The test includes comprehensive debugging output to help understand the parser's behavior with malformed import statements.
Test output shows:
Seeking guidance on the proper implementation to generate a clean LST without J.Erroneous nodes.