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

wrong implied narrowing conversion in compound assignments

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      1.1
    • CPU:
      sparc
    • OS:
      solaris_2.4
    • Verification:
      Not verified

      Description



      Name: swC45995 Date: 11/09/96


      The following assertion do not holds:

      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. Note that the implied cast to type T may be either an identity
      conversion or a narrowing primitive conversion (Java Language Specification,
      section 15.25.2 Compound Assignment Operators)

      Thus, execution of the following test

      public class test
      {
      int field;

      public static void main(String argv[])
      {
      byte b = 1;
      short s = 0x7F7F;
      char c = '\uFFFF';
      int i = 0xFFFFFFFF;
      long l = 2l;
      float f = -3.5f;

      if ((byte)(b ^ s) != (b ^= s))
      System.out.println(0);
      if ((short)(s + 0xC000) != (s += 0xC000))
      System.out.println(1);
      if ((char)(c * 2) != (c *= 2))
      System.out.println(2);
      if ((int)(i & 0xFFF00000FFF0000l) != (i &= 0xFFF00000FFF0000l))
      System.out.println(3);
      if ((long)(l / 1.5f) != (l /= 1.5f))
      System.out.println(4);
      if ((float)(f - Double.MAX_VALUE) != (f -= Double.MAX_VALUE))
      System.out.println(5);
      System.out.println(6);
      }
      }

      produces such output:

      novo40% java test
      3
      4
      5
      6


      instead of expected:

      novo40% java test
      6

      ======================================================================

        Attachments

          Activity

            People

            Assignee:
            busersunw Btplusnull User (Inactive)
            Reporter:
            wensunw Wen Wen (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: