Skip to content

Issue #17158: fix invalid javadoc position for compact constructor#17249

Merged
romani merged 1 commit into
checkstyle:masterfrom
mohitsatr:invalidjavadocpos-record
Jul 27, 2025
Merged

Issue #17158: fix invalid javadoc position for compact constructor#17249
romani merged 1 commit into
checkstyle:masterfrom
mohitsatr:invalidjavadocpos-record

Conversation

@mohitsatr

@mohitsatr mohitsatr commented Jun 20, 2025

Copy link
Copy Markdown
Member

fixes #17158

@mohitsatr

Copy link
Copy Markdown
Member Author

@romani I suppose these tests are old and I must write tests as we write them now for branch coverage purposes right?

@Test
public void testJavaDocsRecognitionNonCompilable() throws Exception {
final List<BlockCommentPositionTestMetadata> metadataList = Arrays.asList(
new BlockCommentPositionTestMetadata("InputBlockCommentPositionOnRecord.java",
BlockCommentPosition::isOnRecord, 3),
new BlockCommentPositionTestMetadata("InputBlockCommentPositionOnCompactCtor.java",
BlockCommentPosition::isOnCompactConstructor, 3)

for (BlockCommentPositionTestMetadata metadata : metadataList) {
final DetailAST ast = JavaParser.parseFile(
new File(getPath(metadata.getFileName())),
JavaParser.Options.WITH_COMMENTS);
final int matches = getJavadocsCount(ast, metadata.getAssertion());
assertWithMessage("Invalid javadoc count")
.that(matches)
.isEqualTo(metadata.getMatchesNum());

@romani

romani commented Jun 22, 2025

Copy link
Copy Markdown
Member

yes, we need coverage for new code in this PR thought Inputs and real Check usage.

pure junit testing as you see it, does not contribute much to quality, as they migh be unrealistic and just test code for main code. One day in future we will convert all such pure unit testing to ent-to-end (Input based testing)

@mohitsatr

Copy link
Copy Markdown
Member Author

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

Comment thread src/main/java/com/puppycrawl/tools/checkstyle/utils/BlockCommentPosition.java Outdated

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.

Just to be on the safe side, please also add this input case so we can ensure that no new false positive is introduced:

PS: If you use a canonical constructor instead of a compact constructor, the error goes away. Similarly, if you use public accessibility instead of package-protected, the error goes away.

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.

done

@github-actions

github-actions Bot commented Jul 1, 2025

Copy link
Copy Markdown
Contributor

@mohitsatr mohitsatr force-pushed the invalidjavadocpos-record branch from 1692554 to b4fcf7a Compare July 2, 2025 07:41

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

Comment thread src/main/java/com/puppycrawl/tools/checkstyle/utils/BlockCommentPosition.java Outdated
@mohitsatr mohitsatr force-pushed the invalidjavadocpos-record branch 2 times, most recently from 412876d to eeebf7b Compare July 7, 2025 11:26
@mohitsatr

Copy link
Copy Markdown
Member Author

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

@github-actions

github-actions Bot commented Jul 7, 2025

Copy link
Copy Markdown
Contributor

@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

Comment thread src/main/java/com/puppycrawl/tools/checkstyle/utils/BlockCommentPosition.java Outdated
@mohitsatr mohitsatr force-pushed the invalidjavadocpos-record branch from eeebf7b to a57a335 Compare July 14, 2025 04:57
@mohitsatr

Copy link
Copy Markdown
Member Author

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

@github-actions

Copy link
Copy Markdown
Contributor

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

please add below suggested cases to the Check's input files too.

Comment on lines +56 to +59
Mapping(String from, String to) {
this.from = from;
this.to = to;
}

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 also add a canonical constructor with public modifier

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.

done

@SizeType(max = 1)
BindMount {}

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 also use public keyword with compact constructor. Similarly for canonical constructor with annotation, create two cases - one with public modifier and other without any modifier.

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.

done

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.

can you also create a top-level record class? it is not necessary but it is always good to have all the cases covered

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.

done

@Zopsss

Zopsss commented Jul 20, 2025

Copy link
Copy Markdown
Member

@mohitsatr let's resume working on this PR. It is almost ready to merge, only few changes are required :)

@mohitsatr mohitsatr force-pushed the invalidjavadocpos-record branch from a57a335 to 4d44910 Compare July 21, 2025 09:05

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

last test extenstion

@mohitsatr mohitsatr force-pushed the invalidjavadocpos-record branch from 4d44910 to 3bd4c48 Compare July 21, 2025 13:51

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

Ok to merge

Comment on lines +87 to +98
public record Mapping2(String to) {

/**
* The constructor for Mapping.
*
* @param to The source
*/
@SizeType(max = 3)
public Mapping2(String to) {
this.to = to;
}
}

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.

The input file is for compact constructors but we have used canonical constructor here. I would suggest to split examples into 2 files - one for compact constructors and second for canonical constructor.

Sorry for asking this but it will make the inputs more manageable and it will also simplify the process of adding more cases in future for other contributors.

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.

Sorry for asking this but it will make the inputs more manageable

no it does make sense.

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.

done

@mohitsatr mohitsatr force-pushed the invalidjavadocpos-record branch from 3bd4c48 to c48f2e5 Compare July 24, 2025 04:33
@mohitsatr mohitsatr force-pushed the invalidjavadocpos-record branch from c48f2e5 to 7781f15 Compare July 24, 2025 05:16
@romani romani merged commit 34a0073 into checkstyle:master Jul 27, 2025
118 checks passed
@mohitsatr mohitsatr deleted the invalidjavadocpos-record branch July 27, 2025 03:13
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.

InvalidJavadocPosition false-positive for record compact constructor with package-private accessibility

3 participants