[squid:S1905] False positive detection of redundant casts

Let’s consider the following method signature.

<M> M getMeta();

Now, if I used this (old) code:

String s = (String) x.getMeta();

a redundant cast is correctly detected.

But this code here:

int l = ( (String) x.getMeta() ).length();

will be reported a false positive redundant cast. And there are quite a lot of them.

Can this be fixed?

The rule key is squid:S1905

hello @MarvinF,

thanks for reporting this issue, I created a ticket to track it https://jira.sonarsource.com/browse/SONARJAVA-3170