java:S6207 - default constructor is seen as redundant while it has an annotation on it

public record SomeDto(
  // properties omitted
) {
  @QueryProjection
  public SomeDto {}
}

We use Querydsl and it generates a class by looking at QueryProjection annotation on the constructor. But Sonarcloud says the declaration of the constructor is redundant. In my opinion, even if the constructor is the same as the default one, it should be considered legitimate if it has annotations on it.

1 Like

Thank you, Namas for reporting this false positive. I created SONARJAVA-4481 to cover this corner case.

We really appreciate your help in improving our rules and products.

Cheers

1 Like

Thanks for the response :grinning: I have one more thing to report. For the exact same code, Sonarcloud also says, by the rule java:S1186, the empty body of the default constructor needs a nested comment explaining why this method is empty. I think this is another case of being false-positive. What do you think, Angelo?

Thank you, Namas.

Regarding the rule java:S1186 it is generally a good practice to nest a comment and clarify what is the intent or give more context to avoid confusion; so I would still recommend adding a comment to help future readers, that are not familiar with the framework, to understand what is going on.

OK, then I’ll make our code compliant with the rule. Thanks for the clarification. :slightly_smiling_face:

1 Like

Oh, I just found that I used the wrong term, but I can’t fix it :sweat_smile:

By ‘default constructor’, I meant ‘compact constructor’.

1 Like