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

Add javac lint warning for possibly lossy conversion in compound assignments

    XMLWordPrintable

    Details

    • Type: CSR
    • Status: Provisional
    • Priority: P4
    • Resolution: Unresolved
    • Fix Version/s: 20
    • Component/s: tools
    • Labels:
      None
    • Subcomponent:
    • Compatibility Kind:
      behavioral
    • Compatibility Risk:
      minimal
    • Compatibility Risk Description:
      New warning.
    • Interface Kind:
      add/remove/modify command line option
    • Scope:
      JDK

      Description

      Summary

      Add a new lint option, lossy-conversions, to javac to warn about type casts in compound assignments with possible lossy conversions.

      Problem

      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;

      Solution

      Warn about possible lossy compound assignments conversions in situations where primitive assignments would fail to compile with possible lossy conversion error.

      Specification

      New text displayed as a key for javac's -Xlint:

           lossy-conversions Warn about possible lossy conversions in compound assignment.

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                Created:
                Updated: