java:S5845 Assertion of LocalDate and some String should be allowed

Version: Current SonarCloud version (I was not able to find some version number…)
Rule: java:S5845 Assertions of dissimilar types should not be made

AssertJ.assertThat(LocalDate.of(2020, 1, 1)).isEqualTo("2020-01-01");

The above java code triggers rule S5845 saying that you should Change the assertion arguments to not compare dissimilar types.
But actually AssertJ implements isEqualTo in this case in AbstractLocalDateAssert which parses the provided String as LocalDate. So the equal check is executed correctly.
Also in my opinion providing the other date as String is usually more readable than creating a LocalDate so it should be supported by sonar as well.

Btw.: This is also an issue for other Temporals of the Java 8 DateTime API and for the old java.util.Date

Hello @sboeing, welcome to the community!

Thanks for the feedback and the clear description of the problem.
I agree with you, and in fact, we already have a ticket to track this issue: SONARJAVA-3466.
Indeed, many types are impacted, feel free to have a look and tell us if we missed one.

Best,
Quentin