Skip to content

Issue #19770: Improve JavadocTypeCheck to handle parameter …#19797

Merged
romani merged 1 commit into
checkstyle:masterfrom
mgustimz:fix/19770-record-component-param
May 16, 2026
Merged

Issue #19770: Improve JavadocTypeCheck to handle parameter …#19797
romani merged 1 commit into
checkstyle:masterfrom
mgustimz:fix/19770-record-component-param

Conversation

@mgustimz

@mgustimz mgustimz commented May 11, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes #19770 - JavadocTypeCheck incorrectly matches record component @param tags using prefix instead of exact match.

Root Cause

In JavadocTypeCheck.checkComponentParamTag(), the matching logic used indexOf() == 0:

.anyMatch(tag -> tag.getFirstArg().indexOf(recordComponentName) == 0);

This means any @param tag whose argument starts with the component name as a prefix would match. For example, with a record component named john, @param john123 was incorrectly treated as documenting john because john123.indexOf(john) == 0.

Fix

Changed to exact match or space-separated match:

.anyMatch(tag -> {
    final String arg = tag.getFirstArg();
    return arg.equals(recordComponentName)
            || arg.startsWith(recordComponentName + " ");
});

This ensures:

  • @param john matches record component john (exact match)
  • @param john some description matches record component john (name + space prefix)
  • @param john123 does NOT match record component john (different name)

The existing checkUnusedParamTags() already uses extractParamNameFromTag() which properly extracts the param name via regex, so it correctly reports john123 as an unused tag.

Testing

Added InputJavadocTypeRecordComponentPrefixMatch.java test case that reproduces the exact scenario from issue #19770.

@mgustimz mgustimz marked this pull request as ready for review May 11, 2026 07:26
@mgustimz mgustimz changed the title Issue checkstyle#19770: Improve JavadocTypeCheck to handle parameter … Issue #19770: Improve JavadocTypeCheck to handle parameter … May 11, 2026
@mgustimz mgustimz force-pushed the fix/19770-record-component-param branch from 5edc68b to ef94ad3 Compare May 11, 2026 08:12
@mgustimz

mgustimz commented May 11, 2026

Copy link
Copy Markdown
Contributor Author

Before fix:
image

After fix:
image

Step to repoduce using the same as mentioned in issue #19770

@mgustimz mgustimz force-pushed the fix/19770-record-component-param branch from e1cd528 to 6062a6c Compare May 11, 2026 10:36
@romani

romani commented May 11, 2026

Copy link
Copy Markdown
Member

Please read and watch playlist videos at Starting_Development.
Please make CI green.

@mgustimz mgustimz force-pushed the fix/19770-record-component-param branch 3 times, most recently from 3de50e9 to b39be4d Compare May 12, 2026 05:44
@mgustimz mgustimz marked this pull request as draft May 12, 2026 05:46
@mgustimz mgustimz force-pushed the fix/19770-record-component-param branch from 7f90b8b to 4cd4f8d Compare May 12, 2026 05:54
@mgustimz mgustimz marked this pull request as ready for review May 12, 2026 05:56
@mgustimz mgustimz force-pushed the fix/19770-record-component-param branch 5 times, most recently from a8dfead to 22ea06a Compare May 12, 2026 17:24
@mgustimz

Copy link
Copy Markdown
Contributor Author

@romani done, please review.

@gianmarcoschifone

Copy link
Copy Markdown
Member

Github, generate report for JavadocType/all-examples-in-one

@github-actions

Copy link
Copy Markdown
Contributor

@gianmarcoschifone

Copy link
Copy Markdown
Member

@romani new violations are expected, ok for me

@romani romani force-pushed the fix/19770-record-component-param branch from 22ea06a to b4bd930 Compare May 13, 2026 12:32

@romani romani left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

items:

@romani

romani commented May 13, 2026

Copy link
Copy Markdown
Member

report is good.

messages in diff report are very confusing, reported #19806 to fix them

@mgustimz mgustimz force-pushed the fix/19770-record-component-param branch 4 times, most recently from c6b3026 to 50022c4 Compare May 13, 2026 14:27
@mgustimz mgustimz marked this pull request as draft May 13, 2026 14:30
@mgustimz mgustimz force-pushed the fix/19770-record-component-param branch from 942072a to 1accef9 Compare May 13, 2026 14:46
@mgustimz mgustimz marked this pull request as ready for review May 13, 2026 14:46
@mgustimz mgustimz requested a review from romani May 13, 2026 14:49
@romani

romani commented May 13, 2026

Copy link
Copy Markdown
Member

@mgustimz mgustimz force-pushed the fix/19770-record-component-param branch from 1accef9 to 60f83ea Compare May 13, 2026 16:59
@mgustimz

Copy link
Copy Markdown
Contributor Author

@romani commit message updated.

@romani romani merged commit c8a31c2 into checkstyle:master May 16, 2026
125 of 126 checks passed
@romani

romani commented May 16, 2026

Copy link
Copy Markdown
Member

@mgustimz , thanks a lot for quick fix, please to work with you

@mgustimz mgustimz deleted the fix/19770-record-component-param branch May 17, 2026 04:11
@mgustimz

Copy link
Copy Markdown
Contributor Author

@romani my pleasure😁

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.

JavadocTypeCheck incorrectly matches record component @param tags using prefix instead of exact match

3 participants