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

Changed behavior of compound assignment (+=)

    XMLWordPrintable

Details

    • Bug
    • Resolution: Not an Issue
    • P4
    • 6-pool
    • 7
    • tools
    • x86
    • windows_7

    Description

      FULL PRODUCT VERSION :
      java version "1.7.0-ea"
      Java(TM) SE Runtime Environment (build 1.7.0-ea-b144)
      Java HotSpot(TM) Client VM (build 21.0-b14, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      A following function cannot be compiled in java 1.6 or less,. but it can be compiled in java 1.7.

      public static void main(String[] args) {
             Object x = "x";
             String y = "y";
             x += i;
      }

      I read http://jdk7.java.net/preview/ and I didn't find this changed behavior in new features.

      REGRESSION. Last worked in version 6u26

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Just write this function
      public static void main(String[] args) {
             Object x = "x";
             String y = "y";
             x += i;
      }
      in any class and try to compile it in different version of jdk.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I was expecting that it will not be compiled.

      Test.java:6: incompatible types
      found : java.lang.Object
      required: java.lang.String
                      x += i;
                      ^
      1 error
      ACTUAL -
      It was compiled.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------

      public class Test {
      public static void main(String[] args) {
      Object x = "A";
      String i = "B";
      x += i;
      }
      }

      ---------- END SOURCE ----------

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: