groovy
  1. groovy
  2. GROOVY-5046

incorrect result when using += operator in closure

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.8.2
    • Fix Version/s: 1.8.3, 1.9-beta-4
    • Component/s: parser
    • Labels:
      None
    • Environment:
      Linux
    • Testcase included:
      yes
    • Number of attachments :
      0

      Description

      I get incorrect result running the following script with groovy 1.8.2:

      a=[3:5]
      
      class B {
              int v;
      }
      
      B b = new B();
      b.v = 3
      
      clos = {
              if (it!=null)
              {
                      a[it.v] += 3
              }
      }
      clos.call(b)
      
      println 'b.v = ' + b.v
      println 'a = ' + a
      

      > groovy test.groovy
      b.v = 8
      a = 8

        Activity

        blackdrag blackdrag made changes -
        Field Original Value New Value
        Description I get incorrect result running the following script with groovy 1.8.2:

        a=[3:5]

        class B {
                int v;
        }

        B b = new B();
        b.v = 3

        clos = {
                if (it!=null)
                {
                        a[it.v] += 3
                }
        }
        clos.call(b)

        println 'b.v = ' + b.v
        println 'a = ' + a


        > groovy test.groovy
        b.v = 8
        a = 8
        I get incorrect result running the following script with groovy 1.8.2:{code:Java}
        a=[3:5]

        class B {
                int v;
        }

        B b = new B();
        b.v = 3

        clos = {
                if (it!=null)
                {
                        a[it.v] += 3
                }
        }
        clos.call(b)

        println 'b.v = ' + b.v
        println 'a = ' + a
        {code}
        > groovy test.groovy
        b.v = 8
        a = 8
        blackdrag blackdrag made changes -
        Status Open [ 1 ] Closed [ 6 ]
        Fix Version/s 1.8.3 [ 17657 ]
        Fix Version/s 1.9-beta-4 [ 17656 ]
        Resolution Fixed [ 1 ]

          People

          • Assignee:
            blackdrag blackdrag
            Reporter:
            Shu-Min Yang
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: