From dev-return-5256-archive-asf-public=cust-asf.ponee.io@groovy.apache.org Mon Aug 20 03:00:25 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 81E71180656 for ; Mon, 20 Aug 2018 03:00:24 +0200 (CEST) Received: (qmail 90416 invoked by uid 500); 20 Aug 2018 01:00:23 -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 90406 invoked by uid 99); 20 Aug 2018 01:00:22 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 20 Aug 2018 01:00:22 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 8B0A01805BE for ; Mon, 20 Aug 2018 01:00:22 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.97 X-Spam-Level: * X-Spam-Status: No, score=1.97 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, HTML_MESSAGE=2, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, T_DKIMWL_WL_MED=-0.01] autolearn=disabled Authentication-Results: spamd3-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=asert-com-au.20150623.gappssmtp.com Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id OhXqTdPZg-wm for ; Mon, 20 Aug 2018 01:00:18 +0000 (UTC) Received: from mail-oi0-f53.google.com (mail-oi0-f53.google.com [209.85.218.53]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTPS id D8D685F107 for ; Mon, 20 Aug 2018 01:00:17 +0000 (UTC) Received: by mail-oi0-f53.google.com with SMTP id d189-v6so23008105oib.6 for ; Sun, 19 Aug 2018 18:00:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=asert-com-au.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:reply-to:from:date:message-id :subject:to; bh=+wK1UC5vft2ZA6W/RfaTSIk0xBCJCkZtBdYHdIzOvvI=; b=AbWcJM5l3Y1FUhq5TzrWhl+Sin1xoZoZsQ6v0v44t6BbxBNfo9jNmpJoW7/YAijPSU lkF+T65hx5dtjzpUoyCWkmsWffkEvILVUmmLx9C8ib6wZmh+laCpLoOt/eEIaV3dQ8nX z8YvTmkOySbrsufHW6xS6Blc7O4wT3kPNMdtC6NBkGeNIiXXSsVQ1SePsHADelzZHrDQ PpkENnTOB49TLMFqXDtxvERLtPcIIvO0NdAmi4+xYXRS4tHf9nDUfasM0OaLF9PZ0+TA WJhfsYrjky1F6MjgIyrRzxg73jzFC3u9pa1Z2vYQ1V1oKy15NqqnrvgwnkhUev1PMgDg LzbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:reply-to :from:date:message-id:subject:to; bh=+wK1UC5vft2ZA6W/RfaTSIk0xBCJCkZtBdYHdIzOvvI=; b=UzU3iU+ochkZTdR4GuK4EnAZYmv0vbWID73In2jIKRm79fr1YI8jbiatjR3CpH+ruH yRNSaDsuJMaArQpOdI5bCwEDksJdpuFzRZafwVIv0Uwxb/9idtCbgLflH+ePkctYAk9W AZiu/ctR9qaYGEoJsvlXfLfxyPqAfWPGPIUtFShl5+tLDEf0nXGpj54rTgRxqz9RkdzO IE4CvB12J3S9VfzgkDjBTL602Lbm+0syFN1F+Dey3exdlVvscdiad5vo8AXo+kt+dQLa Q9oM5jkJuWpC/PPXwbjWO9uwE2U+NvhhOSgnunrvL73a46tOy4cO31NwO1lgX3PuTj0K edmQ== X-Gm-Message-State: AOUpUlGikLZMR1GYOPP5uBiqgFuECwMcbGWi2PxRys8u4MvxgcuugAxs aOncjegElbvFlqS1E4+qC1SJJik8welMFn9CBrqAFygM X-Google-Smtp-Source: AA+uWPwhMdQS07jv29nbkaf3ebEayNz7kOIDOtLKnSuEVbLXk0xRNKhnRgDWoQ7i95DCZffpM6PA6yPDpY8TRjMvKXY= X-Received: by 2002:aca:650d:: with SMTP id m13-v6mr12576866oim.178.1534726810565; Sun, 19 Aug 2018 18:00:10 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Reply-To: paulk@asert.com.au From: Paul King Date: Mon, 20 Aug 2018 10:59:59 +1000 Message-ID: Subject: Re: Inconsistent overriding of Interger methods To: dev@groovy.apache.org Content-Type: multipart/alternative; boundary="0000000000005f38010573d36e5f" --0000000000005f38010573d36e5f Content-Type: text/plain; charset="UTF-8" It appears to be most (all?) primitive/wrapper types not just Integer. On Sun, Aug 19, 2018 at 11:00 PM ocs@ocs wrote: > Ladies and gentlemen, > > the debate of null-propagation led me to bumping into a wildly > inconsistent behaviour when one overrides Integer methods through the > metaclass. > > To me, this looks like a bug; even if this mess happens to be an intended > behaviour, it is pretty weird (in this case, is it documented anywhere?) > > === > 768 */tmp>* java.lang.Integer.metaClass.byteValue={ -> "OK" } > java.lang.Integer.metaClass.plus={ o -> "OK" } > println "byteValue works: ${1.byteValue()}" > println "plus does not: ${1+2}" > println "not even: ${1.plus(2)}" > ArrayList.metaClass.plus={ o -> "OK" } > println "Elsewhere plus works: ${[]+1}" > 768 */tmp>* /usr/local/groovy-3.0.0-alpha-3/bin/groovy q > WARNING: Using incubator modules: jdk.incubator.httpclient > byteValue works: OK > plus does not: 3 > not even: 3 > Elsewhere plus works: OK > 769 */tmp>* > === > > Thanks and all the best, > OC > > --0000000000005f38010573d36e5f Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
It appears to be most (all?) primitive/wrapper types not j= ust Integer.

On Sun, A= ug 19, 2018 at 11:00 PM ocs@ocs <ocs@ocs.c= z> wrote:
Ladies and gentlemen,
the debate of null-propagation led me to bumping into a wildly= inconsistent behaviour when one overrides Integer methods through the meta= class.

To me, this looks like a bug; even if this = mess happens to be an intended behaviour, it is pretty weird (in this case,= is it documented anywhere?)

=3D=3D=3D
768 /tmp> <q.groovy=C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0
java.lang.Integer.metaClass.byteValue=3D{ -> &qu= ot;OK" }
java.lan= g.Integer.metaClass.plus=3D{ o -> "OK" }
println "byteValue works: ${1.byteValu= e()}"
println &qu= ot;plus does not: ${1+2}"
println "not even: ${1.plus(2)}"
ArrayList.metaClass.plus=3D{ o -> "O= K" }
println &quo= t;Elsewhere plus works: ${[]+1}"
768 /tmp> /usr/local/groovy-3.0.0-alpha-3/bin/gro= ovy q
= WARNING: Using i= ncubator modules: jdk.incubator.httpclient
byteValue works: OK
plus does not: 3
not even: 3
Elsewhere plus works: OK
769 /tmp>=C2=A0
=3D=3D=3D

Thanks and al= l the best,
OC

--0000000000005f38010573d36e5f--