Skip to content

Issue #20984: Added new check PreferLiteralJavadocInlineTag - #20397

Draft
Aman-Baliyan wants to merge 1 commit into
checkstyle:masterfrom
Aman-Baliyan:inline
Draft

Issue #20984: Added new check PreferLiteralJavadocInlineTag#20397
Aman-Baliyan wants to merge 1 commit into
checkstyle:masterfrom
Aman-Baliyan:inline

Conversation

@Aman-Baliyan

@Aman-Baliyan Aman-Baliyan commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

@Aman-Baliyan

Copy link
Copy Markdown
Contributor Author

Github, generate report

@github-actions

Copy link
Copy Markdown
Contributor

@romani

romani commented Jun 22, 2026

Copy link
Copy Markdown
Member

please address CI failures

@romani

romani commented Jun 22, 2026

Copy link
Copy Markdown
Member

please read #18570 (comment) we need new property

@romani

romani commented Jun 22, 2026

Copy link
Copy Markdown
Member

on next report generation, please generate report for config without snippet, to keep diff smaller to let us review.

@romani romani added the blocked label Jul 9, 2026
@romani

romani commented Jul 9, 2026

Copy link
Copy Markdown
Member

blocked until we finish coverage table

@romani romani removed the blocked label Jul 19, 2026
@Aman-Baliyan
Aman-Baliyan marked this pull request as draft July 20, 2026 20:08
@Aman-Baliyan
Aman-Baliyan marked this pull request as ready for review July 21, 2026 16:27
@Aman-Baliyan

Copy link
Copy Markdown
Contributor Author

Github, generate report

@Aman-Baliyan

Copy link
Copy Markdown
Contributor Author

Github, generate site

@github-actions

Copy link
Copy Markdown
Contributor

@Aman-Baliyan

Copy link
Copy Markdown
Contributor Author

@romani what jdkVersion should we use in checkstyle-checks.xml. Is it 25 or below 18?
if it is 18 or above then i have create separate pr for violations in checkstyle codes because there are almost 500 violations for <pre> tag

@romani

romani commented Jul 21, 2026

Copy link
Copy Markdown
Member

I do not understand why we need update anything .
plaase share link to problem.

we use jdk21, all jdk25 source goes to non-compiled folders

ok I see, semaphore ....
[ERROR] [checkstyle] [ERROR] /home/semaphore/checkstyle/.ci-temp/sevntu.checkstyle/sevntu-checks/src/main/java/com/github/sevntu/checkstyle/checks/annotation/ForbidAnnotationCheck.java:35:4: Prefer Javadoc inline tag '{@snippet ...}' over '<pre>'. [PreferJavadocInlineTags]

please send supplemental PR to fix this, we eat food we produce, if we can not fix violation, it means Check has problems in design.

sevntu still on jdk11, I hope to upgrade it to jdk21 after release of 13.9.0.
So for now please send update as it is jdk11.

@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.

quick look:

Comment thread config/suppressions.xml
<suppress checks="JavadocStyle" files="JavadocParagraphCheck\.java"/>

<!-- Suppress PreferJavadocInlineTags for all files -->
<suppress checks="PreferJavadocInlineTags"/>

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.

we need to come back to it, we should fix all Inputs of Openjdk for sure.

please point to few problems link and violation with others

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

we need to come back to it, we should fix all Inputs of Openjdk for sure.

please point to few problems link and violation with others

ok i will create a issue for this.

Comment thread config/suppressions.xml Outdated

<!-- JavadocStyle incorrectly parses HTML tags inside {@code} blocks -->
<suppress checks="JavadocStyle"
files="PreferJavadocInlineTagsCheck\.java"/>

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.

remove this , JavadocStyle is removed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

remove this , JavadocStyle is removed.

done

Comment thread config/suppressions.xml Outdated

<!-- JavadocStyle incorrectly parses HTML tags inside {@literal}, {@code} blocks as real HTML,
until #19145 -->
<suppress checks="JavadocStyle" files="JavadocParagraphCheck\.java"/>

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.

#19145 is closed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

#19145 is closed

done

Comment thread config/suppressions.xml Outdated

<!-- EscapedEntity is an error-prone warning, needs @SuppressWarnings to suppress -->
<suppress checks="SuppressWarnings"
files="PreferJavadocInlineTagsCheck\.java"/>

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.

please share details, it is very unusual ....

@Aman-Baliyan Aman-Baliyan Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

please share details, it is very unusual ....

PreferInlineJavadocTagsCheck file contains escaped entity which needs to be suppressed.
I have used the suppression annotation then i got violation from suppression check that's why i have used this

@Aman-Baliyan

Copy link
Copy Markdown
Contributor Author

I do not understand why we need update anything . plaase share link to problem.

we use jdk21, all jdk25 source goes to non-compiled folders

sorry the message #20397 (comment) is not clearly written.

i am asking that i have added a new property jdkVersion in PreferInlineJavadocTagCheck due to snippet inline tag which is added in jdk 18 .
So the question here is what jdkVersion should we used in checkstyle-checks.xml for PreferInlineJavadocTagCheck
because there are huge violations from snippet tag in checkstyle javadocs.

The violations are -> https://checkstyle-diff-reports.s3.us-east-2.amazonaws.com/1dbbeec_2026171053/reports/diff/checkstyle/index.html

@Aman-Baliyan

Copy link
Copy Markdown
Contributor Author

sevntu still on jdk11, I hope to upgrade it to jdk21 after release of 13.9.0.
So for now please send update as it is jdk11.

if it is on jdk11 then violation for pre tag cannot be resolved. Should we use jdkVersion less than 18 for now in checkstyle-checks.xml for PreferJavadocInlineTags.

@romani

romani commented Jul 22, 2026

Copy link
Copy Markdown
Member

yes, it will good example on what update is expected for jdk21 and for jdk18. Pretty sad that fixes are different.
give me some small preview of updates to let me feel a pain.
Over-demanding Checks usually doomed to die in no-usage, we need to try to make it less painful.

@Aman-Baliyan

Aman-Baliyan commented Jul 23, 2026

Copy link
Copy Markdown
Contributor Author

give me some small preview of updates to let me feel a pain.

Example -> if we use jdkVersion >= 18 then we have to change the <pre> tag with {@snippet} inline tag as given below:

    // violation below

    /**
     * Content inside pre blocks should be ignored:
     * <pre>
     * &lt;code&gt;sample&lt;/code&gt;
     * &lt;a href="#method"&gt;link&lt;/a&gt;
     * </pre>
     */
    public void insidePreBlock() {
    }

   // violation fixed
  
    /**
     * Content inside snippet blocks should be ignored:
     * {@snippet :
     * <code>sample</code>
     * <a href="#method">link</a>
     * }
     */
    public void insideSnippetTag() {
    }


Although there is a advantage of using snippet tag because we do not need escaping characters inside it like pre.

@Aman-Baliyan

Copy link
Copy Markdown
Contributor Author

working on ci/semaphore failures.

@Aman-Baliyan
Aman-Baliyan marked this pull request as draft July 23, 2026 18:44
@romani

romani commented Jul 23, 2026

Copy link
Copy Markdown
Member

@Aman-Baliyan , what is refactoring for jdk < 18 ?

is it same but @code should be used ?

ok, I see:
[ERROR] [checkstyle] [ERROR] /home/semaphore/checkstyle/.ci-temp/sevntu.checkstyle/sevntu-checks/src/main/java/com/github/sevntu/checkstyle/checks/coding/UnnecessaryParenthesesExtendedCheck.java:340:16: Prefer Javadoc inline tag '{@code ...}' over '<code>'. [PreferJavadocInlineTags]
https://github.com/sevntu-checkstyle/sevntu.checkstyle/blob/f852bff1047f2669ff06e17aec3676cd094c1ce5/sevntu-checks/src/main/java/com/github/sevntu/checkstyle/checks/coding/UnnecessaryParenthesesExtendedCheck.java#L43-L45

now I am thinking that we do not need to new property.
@code - Short, single-line code text.
@snippet - Rich, multi-line code examples.

https://openjdk.org/jeps/413

Although {@code ...} can be used by itself for small fragments of code, .....

So there is two migrations:
single-line and and <pre>&lt;code&gt... all escaped content - to {@code or {@snippet.
multi-line and and <pre>&lt;code&gt... all escaped content - to {@snippet.
multi-line and <pre>{@code ... - to {@snippet.
single-line and {@code ... (no <pre>) should be ok.

World is moved to jdk21, so all new javadoc tags are already out and this is most used jdk in world. old code will continue to stay with old jdk, no need to change that legacy code that works and docs are written.
Checkstyle is already using jdk21 as minimal requirements. So it means that this Check can be run only in jdk21, so no need for such property. Users naturally forced to use jdk21 minimum.

So our logic should be fully focus on chunks that are multi-line or single-line and suggest to upgrade.

May be in future users will ask us to make special property to always demand @snippet but it will be in far future, and we will get to know in what case @code is not good.

Do you agree with me ?

@Aman-Baliyan

Copy link
Copy Markdown
Contributor Author

Do you agree with me ?

i agree with u.
So in this pr which one should we cover PreferJavadocLiteralInlineTags, PreferJavadocCodeOrSnippetInlineTags, PreferLinkJavadocInlineTag.

@romani

romani commented Jul 24, 2026

Copy link
Copy Markdown
Member

up to you, you can close this PR and start new to not be confusing, might be the best approach.

start from PreferJavadocLiteralInlineTags (sounds like easy Check), then PreferJavadocCodeOrSnippetInlineTags

PreferLinkJavadocInlineTag is not clear for me, lets have issue creation for now and share there details ..

@Aman-Baliyan

Copy link
Copy Markdown
Contributor Author

up to you, you can close this PR and start new to not be confusing, might be the best approach.

start from PreferJavadocLiteralInlineTags (sounds like easy Check), then PreferJavadocCodeOrSnippetInlineTags

PreferLinkJavadocInlineTag is not clear for me, lets have issue creation for now and share there details ..

as this pr contains a lot of work so better option is to change its description and names only . I will changed it to PreferJavadocLiteralInlineTags.

@Aman-Baliyan

Aman-Baliyan commented Jul 25, 2026

Copy link
Copy Markdown
Contributor Author

i will create a parent a umbrella issue for these check and create sub-issues for literal, link and code.

@Aman-Baliyan

Copy link
Copy Markdown
Contributor Author

#20980

@Aman-Baliyan Aman-Baliyan changed the title Issue #18570: Added new check PreferJavadocInlineTags Issue #20984: Added new check PreferLiteralJavadocInlineTag Jul 27, 2026
@Aman-Baliyan

Copy link
Copy Markdown
Contributor Author

Current Implementation of this check ->

This check will flag -> &lt; and &gt; html entities.
Text inside code and pre html tags are skipped.
Text inside code, literal, snippet tags are skipped

@Aman-Baliyan

Copy link
Copy Markdown
Contributor Author

@romani , according to current implementation we takes a text line traverse the line through loops and through violations for each entity found. Is this good?
Or should we throw a single error for all similar type of entities in a line.

By example ->

/**
 * Multiple: &lt;T&gt; and &lt;E&gt; generics.
 */
public class InputPreferLiteralJavadocInlineTagMultipleEntities {
}

Current ,

// 4 violations:
// 'Prefer Javadoc inline tag '{@literal <}' over '<'.'
// 'Prefer Javadoc inline tag '{@literal >}' over '>'.'
// 'Prefer Javadoc inline tag '{@literal <}' over '<'.'
// 'Prefer Javadoc inline tag '{@literal >}' over '>'.'

Should i change it to only 2 violations ->

// 'Prefer Javadoc inline tag '{@literal <}' over '<'.'
// 'Prefer Javadoc inline tag '{@literal >}' over '>'.'

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.

2 participants