False positive S5853 (assertThat statements should be chained)

Hi,

This unit test reports an issue on first line, saying that the second assertThat statement should be chained with the first one, but it’s not possible because of the element(0) call. Or is there a good way to chain element(int) calls?

assertThat(list).isNotNull().hasSize(30)
    .element(0).returns("comment", FoldingRange::getKind);
assertThat(list).element(1).returns("comment", FoldingRange::getKind);

Sonarqube EE 2026.1 (119033)

Gilles

Hello @gquerret, thank you for your message. This issue is indeed a false positive due to the way the element method is handled. I have opened a ticket to fix this.