Rule:
S3052: Fields should not be initialized to default values
Description:
Unable to detect assignment which right statement has a type conversion, for example: byte foo = (byte)0,
This rule is implemented in sonar-java-plugin-6.1.0.20866\org\sonar\java\checks\DefaultInitializedFieldCheck.java,
This rule converts the assignment(LiteralUtils.longLiteralValue(expression);
, Double.valueOf(((LiteralTree) expression).value()
) after using switch to classify the variable type(case CHAR_LITERAL:
, case BOOLEAN_LITERAL:
)
When there is a type conversion on the right side of the assignment statement, the value conversion may be wrong.
Code Sample demonstrating the issue:
private byte lastByte=(byte)0;
private float _currAlpha = (float)0.0;
Expected outcome:
false-negative
Running Sonarqube through:
command line