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 cust-asf.ponee.io (Postfix) with SMTP id A93C516794E for ; Tue, 22 Aug 2017 22:45:05 +0200 (CEST) Received: (qmail 92350 invoked by uid 500); 22 Aug 2017 20:45:04 -0000 Mailing-List: contact dev-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 dev@groovy.apache.org Received: (qmail 92340 invoked by uid 99); 22 Aug 2017 20:45:04 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 22 Aug 2017 20:45:04 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id F275CC03E5 for ; Tue, 22 Aug 2017 20:45:03 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -0.901 X-Spam-Level: X-Spam-Status: No, score=-0.901 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HTML_MESSAGE=2, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-2.8, SPF_PASS=-0.001] autolearn=disabled Authentication-Results: spamd1-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id R9vtCbvpdBR8 for ; Tue, 22 Aug 2017 20:45:03 +0000 (UTC) Received: from mail-wr0-f182.google.com (mail-wr0-f182.google.com [209.85.128.182]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTPS id E1E77611A7 for ; Tue, 22 Aug 2017 20:45:02 +0000 (UTC) Received: by mail-wr0-f182.google.com with SMTP id p14so62448567wrg.1 for ; Tue, 22 Aug 2017 13:45:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=Pb5XKxnpjhyfO1gOBBXgTaxd9i1buzeIt+PSo4Qor0c=; b=BFqlmQ/+P6tBBDVKfe5fwx4bi3WpcQftYcwj/Txtoimt/HekrwZjXn4VKcFjkINJfN 7oUdHyy/3yKPzFnVS6PBSFaBJrvRnFHLWJnPriFzdNXj5kujp0A5sNhlyGKncvWymFHr DuZn5gEqieDFxwqkJSf6dLyysTUiDGO/QuPutp6130zlwprhlbDTUT0i8zsZRgdgFjcO CDCReo6oKQCbYEKXk6tFjvKutUm1otItHkuJ3yOWMZ1IDmmr91MpT16TxVIY6NUeNunK MrfhXwf8bxd6qk0DvWYaupuggT3Ts1MyXu2O+dpclyPbiD1DPUfa+TIb40I46xkoKOH6 XhYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=Pb5XKxnpjhyfO1gOBBXgTaxd9i1buzeIt+PSo4Qor0c=; b=HFTaaArfjpLxwHL1ymzyJpMY5S0PixB+mNnnsXAmn+enuIyYLwEurE6Tjg/gbYG+v9 //Ua13dUIFWWxwayweZqw6EKzdtglzekVjDjJZyb4iagHETtEz7RpsuQ+LbBV6Ck0Uua +AeSCn2QB5fN6/rxs82W4vIUoK/7YR9nALMdO0Mcn70QsiLsk3/rQcmECK2LF1VtK9iF gK68pg4wkE4A8+b9GrD8vNy7brt6CnkrFFgtWIZ7mrzHNsxcQWOX5TCrF9B8b6vuaO7/ PbAFtzPbtZZMmL01bY+ODFwoSgEwu7sLszZ7PexYvz9wRl5tWX4GB3Wuwd27gzi2hwn7 NcaA== X-Gm-Message-State: AHYfb5j03OCzIh3XNepunl1667Ocr2VIWMDbUQZ1EamW5PObxvHx7Rzn vngLXZrQhswA9hUnT8ZC6Zf4NdF/NNoE X-Received: by 10.223.171.209 with SMTP id s75mr143947wrc.277.1503434701923; Tue, 22 Aug 2017 13:45:01 -0700 (PDT) MIME-Version: 1.0 Received: by 10.28.230.199 with HTTP; Tue, 22 Aug 2017 13:44:41 -0700 (PDT) In-Reply-To: <719a4011-837f-095d-b744-3e043111322d@gmx.org> References: <719a4011-837f-095d-b744-3e043111322d@gmx.org> From: Andrew Bayer Date: Tue, 22 Aug 2017 16:44:41 -0400 Message-ID: Subject: Re: How does Groovy decide to coerce a GString to a String at method dispatch? To: Jochen Theodorou Cc: dev@groovy.apache.org Content-Type: multipart/alternative; boundary="001a11470a3859ea9605575dabf7" --001a11470a3859ea9605575dabf7 Content-Type: text/plain; charset="UTF-8" I'll answer in more detail later, but it's a LinkedHashMap.get that's being called. A. On Tue, Aug 22, 2017 at 4:34 PM, Jochen Theodorou wrote: > On 22.08.2017 00:53, Andrew Bayer wrote: > >> Hey all - >> >> I'm working on an issue in Jenkins' Groovy sandboxing logic - >> https://issues.jenkins-ci.org/browse/JENKINS-46327. The problem is that >> 'map."some${variable}"' seems to be acting as if the GStringImpl was the >> key, rather than the String it should coerce to. I've got a feeling this is >> due to a flaw in our sandbox's method dispatch code somewhere, so I'm >> trying to figure out how Groovy is deciding to coerce normally. And I can't >> tell where that would be. =) Anyone got any pointers? >> > > it is legal to call get(String) with a String, but the transformation > happens during the method call by the runtime. Method dispatch in the meta > class is deciding about what method is to be taken. It is different for > static compilation of course. > > Now if you have a list of all the get-methods that are available I can > easily tell you which method will be called and why. So for example if you > have get(String), get(Object) and get(CharSequence) a call to that method > with a GString will call the CharSequence method, because that is an > interface GString is implementing. If that methods would be not there it > would have been get(String), because String is seen as more near to GString > than Object for the runtime. Obviously this is not following strictly the > class hierarchy > > bye Jochen > > --001a11470a3859ea9605575dabf7 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
I'll answer in more detail later, but it's a Linke= dHashMap.get that's being called.

A.

On Tue, Aug 22, 2017 = at 4:34 PM, Jochen Theodorou <blackdrag@gmx.org> wrote:
<= blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px= #ccc solid;padding-left:1ex">On 22.08.2017 00:53, Andre= w Bayer wrote:
Hey all -

I'm working on an issue in Jenkins' Groovy sandboxing logic - https://issues.jenkins-ci.org/browse/JENKINS-46327= . The problem is that 'map."some${variable}"' seems t= o be acting as if the GStringImpl was the key, rather than the String it sh= ould coerce to. I've got a feeling this is due to a flaw in our sandbox= 's method dispatch code somewhere, so I'm trying to figure out how = Groovy is deciding to coerce normally. And I can't tell where that woul= d be. =3D) Anyone got any pointers?

it is legal to call get(String) with a String, but the transformation happe= ns during the method call by the runtime. Method dispatch in the meta class= is deciding about what method is to be taken. It is different for static c= ompilation of course.

Now if you have a list of all the get-methods that are available I can easi= ly tell you which method will be called and why. So for example if you have= get(String), get(Object) and get(CharSequence) a call to that method with = a GString will call the CharSequence method, because that is an interface G= String is implementing. If that methods would be not there it would have be= en get(String), because String is seen as more near to GString than Object = for the runtime. Obviously this is not following strictly the class hierarc= hy

bye Jochen


--001a11470a3859ea9605575dabf7--