Add a new lint option,
javac to warn about type casts in compound assignments with possible lossy conversions.
If the type of the right-hand operand of a compound assignment is not assignment compatible with the type of the variable, a cast is implied and possible lossy conversion may silently occur. While similar situations are resolved as compilation errors for primitive assignments, there are no similar rules defined for compound assignments. Following simple assignments cause compilation errors:
int i = 0; i = i * Double.NaN; byte b = 257;
While following compound assignments compile without any error or warning:
int i = 0; i *= Double.NaN; byte b = 0; b += 257;
Warn about possible lossy compound assignments conversions in situations where primitive assignments would fail to compile with possible lossy conversion error.
New text displayed as a key for
lossy-conversions Warn about possible lossy conversions in compound assignment.