Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SonarQube Java Analyser, rule S2183, why should I remove this useless shift?

Tags:

java

sonarqube

I have written:

public static final int MY_GREAT_COLOR = (91 << 16) + (155 << 8) + 213 + (255 << 32);

And sonar says:

New: Squid:S2183 Severity: CRITICAL, Message: Remove this useless shift

Could anybody tell me why? Is that only the fact that there should be no calculations on literals, even if it adds to readability?

like image 823
Marcin Szawurski Avatar asked Jun 26 '15 13:06

Marcin Szawurski


1 Answers

I guess 255 is your alpha channel, in that case I guess you wanted 255 << 24.

SonarQube doesn't know your intentions, but it has a valid point, as Toby stated.

As for readability, you can also try hexa code (e.g. 0xFF5B9BD5), many devs are used to that already. Of course, a decimal number would be totally unreadable and ugly.

like image 84
Vlasec Avatar answered Oct 19 '22 03:10

Vlasec