[false-negative]S3052 can not detect assignment which right statement has a type conversion

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

1 Like

Hey @wongwuchiu,

Sorry for the late reply, this is indeed a False Negative (FN) and we should be able to fix it easily.
I created the following ticket to handle it: SONARJAVA-3503.

Cheers,
Michael

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.