Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8244681

Add a warning for possibly lossy conversion in compound assignments

    Details

      Description

      ADDITIONAL SYSTEM INFORMATION :
      openjdk version "13" 2019-09-17
      OpenJDK Runtime Environment (build 13+33-Ubuntu-1)


      A DESCRIPTION OF THE PROBLEM :
      Normally, when a computation with a long and a double variable is performed then javac produces an incompatible types error as illustrate in the following example:

      long a = 1L + 0.1 * 3L; // produces error: incompatible types: possible lossy conversion from double to long

      However, when the same computation is done with an "+=" operator (or also with similar operators, like "-="), then this error does not occur:

      long b = 1L;
      b += 0.1 * 3L;

      Since this error is helpful to detect unwanted usages of variables or etc., it would be good to show it in all situations, where it can occur.


      FREQUENCY : always


        Attachments

          Activity

            People

            • Assignee:
              asotona Adam Sotona
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated: