Skip to content

Conversation

@andreaguarino
Copy link
Contributor

@andreaguarino andreaguarino commented Oct 23, 2025

SONARJAVA-5803

Part of

@andreaguarino andreaguarino marked this pull request as ready for review October 23, 2025 13:27
Copy link
Contributor

@GabrielFleischer GabrielFleischer left a comment

Choose a reason for hiding this comment

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

There are some worrying changes in the tests. I would happily help to investigate them.

@NullMarked // Compliant
class Inner {
@NonNull Object o; // Noncompliant {{Remove redundant annotation @NonNull as inside scope annotation @NullMarked at class level.}}
@NonNull Object o; // Compliant
Copy link
Contributor

Choose a reason for hiding this comment

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

If I am not mistaken, this is indeed noncompliant.

As the class is annotated with @NullMarked, everything is assumed to be nonnull except if it is annotated with @Nullable.

So @NonNull is redundant.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, thanks for catching this!

@NullMarked // Compliant
class Inner {
@NullMarked // Noncompliant {{Remove redundant annotation @NullMarked at class level as inside scope annotation @NullMarked at class level.}}
@NullMarked // Compliant
Copy link
Contributor

Choose a reason for hiding this comment

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

This is also Noncompliant, the class is transitively NullMarked.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, thanks!

@NullUnmarked // Compliant
class Inner {
@NullUnmarked // Noncompliant {{Remove redundant annotation @NullUnmarked at class level as inside scope annotation @NullUnmarked at class level.}}
@NullUnmarked // Compliant
Copy link
Contributor

Choose a reason for hiding this comment

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

And this is redundant too.

I wonder what caused this to change...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the implementation, we're only checking for nullabilityData being either "isNonNull" or "isNullable", so we don't check for redundant annotations with unknown nullabilities. I'm not sure if it's worth changing this, as it would change quite a bit the implementation

Comment on lines 21 to +22
@NullUnmarked
protected abstract boolean isBool(); // Noncompliant {{"@NullUnmarked" annotation should not be used on primitive types}} [[quickfixes=qf1]]
// ^^^^^^^
// fix@qf1 {{Remove "@NullUnmarked"}}
// edit@qf1 [[sl=-1;el=+0;sc=3;ec=3]] {{}}
protected abstract boolean isBool(); // Compliant - NullUnmarked doesn't add any information about nullability
Copy link
Contributor

Choose a reason for hiding this comment

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

I think using @NullUnmarked in these tests was a mistake. We should migrate to @Nullable as the test is doesn't prove anything otherwise...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the test was there to assert how the check "PrimitivesMarkedNullableCheck" behave in presence of "@NullMarked" / "@NullUnmarked" annotations, so I'm not sure we should replace it with "@nullable" because it's already asserted inside "checks/PrimitivesMarkedNullableCheckSample". So maybe we should just remove this test file

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I eventually decided to let the existing testcase and just replace the Noncompliant -> Compliant, to still verify we don't raise FPs

@sonarqube-next
Copy link

Copy link
Contributor

@GabrielFleischer GabrielFleischer left a comment

Choose a reason for hiding this comment

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

LGTM

@andreaguarino andreaguarino merged commit 22044bb into master Oct 27, 2025
17 of 18 checks passed
@andreaguarino andreaguarino deleted the SONARJAVA-5803 branch October 27, 2025 14:55
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