From notifications-return-11936-archive-asf-public=cust-asf.ponee.io@groovy.apache.org Sat Apr 21 09:47:04 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 44D9218064C for ; Sat, 21 Apr 2018 09:47:04 +0200 (CEST) Received: (qmail 74558 invoked by uid 500); 21 Apr 2018 07:47:02 -0000 Mailing-List: contact notifications-help@groovy.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@groovy.apache.org Delivered-To: mailing list notifications@groovy.apache.org Received: (qmail 74549 invoked by uid 99); 21 Apr 2018 07:47:02 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 21 Apr 2018 07:47:02 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 4EB7C1A06EE for ; Sat, 21 Apr 2018 07:47:02 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -101.511 X-Spam-Level: X-Spam-Status: No, score=-101.511 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, RCVD_IN_DNSWL_MED=-2.3, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id pV9Bd4fK_il2 for ; Sat, 21 Apr 2018 07:47:01 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTP id 333A85F5B3 for ; Sat, 21 Apr 2018 07:47:01 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id A1B01E00C4 for ; Sat, 21 Apr 2018 07:47:00 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id 5C53C2403C for ; Sat, 21 Apr 2018 07:47:00 +0000 (UTC) Date: Sat, 21 Apr 2018 07:47:00 +0000 (UTC) From: "Jochen Theodorou (JIRA)" To: notifications@groovy.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (GROOVY-8555) The private keyword of an instance variable is causing a behavior change in a map class MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/GROOVY-8555?page=3Dcom.atlassia= n.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=3D164= 46675#comment-16446675 ]=20 Jochen Theodorou commented on GROOVY-8555: ------------------------------------------ x.y is using property access logic in Groovy, not field access logic, field= access is done via @, in like x.@y. This means your cloned.a is a property access. On a map property access sets the content of a map, unless there is an expl= icit property defined. String a =3D 'a'; in your class defines property a, thus clone.a=3D... will not write the map= , it will write the property.Similar println(cloned.a) will read the proper= ty private String a =3D 'a'; in your class defines no property a, only the field, thus clone.a=3D... wil= l write an entry into the map. Similar println(cloned.a) will read the map. > The private keyword of an instance variable is causing a behavior change = in a map class > -------------------------------------------------------------------------= -------------- > > Key: GROOVY-8555 > URL: https://issues.apache.org/jira/browse/GROOVY-8555 > Project: Groovy > Issue Type: Bug > Affects Versions: 2.4.12 > Reporter: Howard > Assignee: Jochen Theodorou > Priority: Major > > h1. Problem: Adding the private keyword causes a difference in behavior w= hen using the dot operator > Consider the following 2 scripts with the same class (1 with the instance= variable declared as private with everything else being the same) > h2. Script 1: > {code:java} > import java.util.concurrent.ConcurrentHashMap > import groovy.transform.CompileStatic > class mymap extends ConcurrentHashMap{ > private String a =3D 'a'; > def cloned(){ > def clone =3D new mymap() > clone.putAll(this) > clone.a =3D this.a > return clone > } > } > def mm =3D new mymap() > def fieldA =3D mymap.class.getDeclaredField("a") > fieldA.setAccessible(true) > mm.b =3D 'b' > def cloned =3D mm.cloned() > println(cloned.a) > println(fieldA.get(cloned)) > println(cloned) > =C2=A0{code} > h2. Output: > {code} > a > a > [a:a, b:b] > {code} > h2. Script 2: > {code} > import java.util.concurrent.ConcurrentHashMap > import groovy.transform.CompileStatic > class mymap extends ConcurrentHashMap{ > String a =3D 'a'; > def cloned(){ > def clone =3D new mymap() > clone.putAll(this) > clone.a =3D this.a > return clone > } > } > def mm =3D new mymap() > def fieldA =3D mymap.class.getDeclaredField("a") > fieldA.setAccessible(true) > mm.b =3D 'b' > def cloned =3D mm.cloned() > println(cloned.a) > println(fieldA.get(cloned)) > println(cloned) > {code} > h2. Output: > {code} > null > a > [b:b] > {code} > h1. Expectation > Adding the 'private' keyword in front of the instance variable should not= change the output of these 2 scripts -- This message was sent by Atlassian JIRA (v7.6.3#76005)