JDK-8251249 : Float value stores in int with loss of precision when using += (compound assignment Operato)
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 8u261
  • Priority: P3
  • Status: Closed
  • Resolution: Not an Issue
  • OS: generic
  • CPU: generic
  • Submitted: 2020-08-06
  • Updated: 2020-08-06
  • Resolved: 2020-08-06
Description
ADDITIONAL SYSTEM INFORMATION :
WINDOWS LINUX

A DESCRIPTION OF THE PROBLEM :
int intValue = 3;
// error
intValue = intValue + 0.5;

// no error, and can excuate
intValue += 0.5;

REGRESSION : Last worked in version 8u261


FREQUENCY : always



Comments
This is not an issue. A compound assignment expression of the form E1 op= E2 is equivalent to E1 = (T)((E1) op (E2)), where T is the type of E1, except that E1 is evaluated only once. Please go through https://docs.oracle.com/javase/specs/jls/se14/html/jls-15.html#jls-15.26.2 This is also explained at https://stackoverflow.com/questions/8710619/why-dont-javas-compound-assignment-operators-require-casting?noredirect=1&lq=1
06-08-2020