I’m trying your new AspectJ rules, and in particular java:S5841.
In your compliant solution section, you suggest
Which is not possible, since
isEmpty() returns void.
Also, on a separate note, I believe that
doesNotContain should not be included in this rule, or at least
doesNotContain should be separate rules. The semantics are very different.
For example it’s very common to say “this list should not contain something” and not care about the list’s size, but very rare to say “this list should not contain something and also not be empty”.
On the other hand your
allMatch example in the rule definition makes absolute sense:
assertThat(logs).allMatch(e -> e.contains(“error”)); // Noncompliant, this test pass if logs are empty!
Also from a programmatic point of view, a “naked”
allMatch can be matched (as suggested) with
isNotEmpty(), where a “naked”
doesNotContain cannot be matched with an
isEmpty() (as wrongly suggested).