Skip to content

Handle invalid JavaDoc references in parser and printer#5535

Merged
timtebeek merged 2 commits into
mainfrom
invalid-reference-in-javadov-print-idempotency
Jun 2, 2025
Merged

Handle invalid JavaDoc references in parser and printer#5535
timtebeek merged 2 commits into
mainfrom
invalid-reference-in-javadov-print-idempotency

Conversation

@timtebeek

@timtebeek timtebeek commented Jun 1, 2025

Copy link
Copy Markdown
Member

@timtebeek timtebeek requested a review from greg-at-moderne June 1, 2025 21:47
@timtebeek timtebeek self-assigned this Jun 1, 2025
@timtebeek timtebeek added bug Something isn't working javadoc labels Jun 1, 2025
@github-project-automation github-project-automation Bot moved this to In Progress in OpenRewrite Jun 1, 2025
qualifier == null ? Space.EMPTY : qualifier.getPrefix(),
Markers.EMPTY,
qualifier == null ? null : JRightPadded.build(qualifier.withPrefix(Space.EMPTY)),
JRightPadded.build(qualifier == null ? null : qualifier.withPrefix(Space.EMPTY)),

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This mimics what we do for the Java parser: there we also unconditionally create a JRightPadded with a nullable containing element.

Comment on lines +403 to +405
visitLeftPadded("#", memberRef.getPadding().getReference(), JLeftPadded.Location.MEMBER_REFERENCE_NAME, p);
} else {
visitLeftPadded(null, memberRef.getPadding().getReference(), JLeftPadded.Location.MEMBER_REFERENCE_NAME, p);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

These visitLeftPadded might be a little too hyper focused on the failing test that was provided, but still I think it's common enough to keep this as is here. If we were to unconditionally use a # prefix, then that would be another print idempotency issue.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think I see what you mean here. But I see no better option.

@timtebeek timtebeek moved this from In Progress to Ready to Review in OpenRewrite Jun 1, 2025
@greg-at-moderne

Copy link
Copy Markdown
Contributor
JavadocTest > parsingIncorrectJavadocValueReference() FAILED
    java.lang.IllegalStateException: LST contains missing or invalid type information
    Identifier->InlinedValue->DocComment->MethodDeclaration->Block->ClassDeclaration->CompilationUnit
    /*~~(Identifier type is missing or malformed)~~>*/BAR
    https://docs.openrewrite.org/reference/faq#im-seeing-lst-contains-missing-or-invalid-type-information-in-my-recipe-unit-tests-how-to-resolve
is the CI failure.

@timtebeek

Copy link
Copy Markdown
Member Author

Thanks! Weird how those only show on Java 11 and 17; they are true, and expected, so I've updated the recipe spec to allow for those, as indeed we're using an invalid reference; we're aiming for print idempotency, not type fixes.

@greg-at-moderne greg-at-moderne left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@timtebeek timtebeek merged commit 117414b into main Jun 2, 2025
2 checks passed
@timtebeek timtebeek deleted the invalid-reference-in-javadov-print-idempotency branch June 2, 2025 13:17
@github-project-automation github-project-automation Bot moved this from Ready to Review to Done in OpenRewrite Jun 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working javadoc

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Parsing invalid Javadoc reference fails

2 participants