Skip to content

Conversation

mohitsatr
Copy link
Member

@mohitsatr mohitsatr commented Jun 20, 2025

fixes #17158

@mohitsatr
Copy link
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
Copy link
Member

romani commented Jun 22, 2025

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
Member Author

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

Copy link
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
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
Contributor

github-actions bot commented Jul 1, 2025

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

@romani romani left a comment

Choose a reason for hiding this comment

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

items:

@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
Member Author

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

Copy link
Contributor

github-actions bot commented Jul 7, 2025

Copy link
Member

@romani romani left a comment

Choose a reason for hiding this comment

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

Items

@mohitsatr mohitsatr force-pushed the invalidjavadocpos-record branch from eeebf7b to a57a335 Compare July 14, 2025 04:57
@mohitsatr
Copy link
Member Author

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

Copy link
Contributor

Copy link
Member

@Zopsss Zopsss left a comment

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
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
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
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
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
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
Member Author

Choose a reason for hiding this comment

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

done

@Zopsss
Copy link
Member

Zopsss commented Jul 20, 2025

@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
Copy link
Member

@romani romani left a comment

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
Copy link
Member

@romani romani left a comment

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