From dev-return-5394-archive-asf-public=cust-asf.ponee.io@groovy.apache.org Wed Sep 12 06:40:18 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 18280180630 for ; Wed, 12 Sep 2018 06:40:17 +0200 (CEST) Received: (qmail 29684 invoked by uid 500); 12 Sep 2018 04:40:17 -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 29672 invoked by uid 99); 12 Sep 2018 04:40:16 -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; Wed, 12 Sep 2018 04:40:15 +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 7F2AA186A1B for ; Wed, 12 Sep 2018 04:40:15 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.889 X-Spam-Level: * X-Spam-Status: No, score=1.889 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, SPF_PASS=-0.001, T_DKIMWL_WL_MED=-0.01] autolearn=disabled Authentication-Results: spamd3-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.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 KFswpF8p6Fyh for ; Wed, 12 Sep 2018 04:40:14 +0000 (UTC) Received: from mail-io0-f171.google.com (mail-io0-f171.google.com [209.85.223.171]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTPS id 4EEF75F491 for ; Wed, 12 Sep 2018 04:40:13 +0000 (UTC) Received: by mail-io0-f171.google.com with SMTP id 75-v6so436154iou.11 for ; Tue, 11 Sep 2018 21:40:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=dJmpQWcV4LsqbqoOG3vrjRw/In/Z/krUGMOtee6WlWU=; b=RJ8DP4xCe5cnd1EDI6uP4TEwwRaNtlCPIbmWr2Zk+/DoHbX0QcBycUYIF9E/Jgct0h 10IJNvy4vt2brDbdD6rURm2sBUy4RsXtRnB5rbhYVqo3df1UjYsDZPRG3f4l+QJpBmoW rjJf1lpBXQ9ZJ3C1sfu2HJsXd5t9TZRFhHUYz9VcsbcUyQF/s5g+WZHYaTU5RG4s/idy Fr11Zwux5N9lg8+JPXYbJOG0tV/hu8ikneXczbDpeiryO0c17dxIoXC6qGNX6INrUHVF FrNSxALrDGueRuknnRLwhcKdXY31K2FA3UN8+cy8WwDr3whaDHszqmquuFl0TRAagcTO M5bA== 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:from:date :message-id:subject:to; bh=dJmpQWcV4LsqbqoOG3vrjRw/In/Z/krUGMOtee6WlWU=; b=K/nBNhvuep1tXcqVKPlMwjt2U3oET7rPSjIOlJxhc8fbQILCy7E1pJiw6m8D83ijMv Th/Jd7TXM0fatZG8Bk0N2hTN8VZjJW/0qORBkwfqZ+g5YLaFNYxi8ALHn0H3SAXATB+u R6kQKEJw2+4E0HqSZcnlkURDZunLwwBnVYrPRibxULpgJyCjX/CtriCwUE/U2KS54kyQ uCW07rXSpji0BUS/loO9XULo1HQZftRQNlnJDhE0my2i3ahG754CPcJQWV9LQLavMHuw yGj8ljEHheT3NdU4iBAQCKKhg+NmouwXUJkCYdg2C6mJ/L7lLpCJ7/zDKCqBMAOlcK6g hISA== X-Gm-Message-State: APzg51Auhaxw6o5Xu0Tqs9x/Ew1WBlR9cBdjsk6JiJklKJVBSt7Q1zfh MoAWy4boU3kCMVuLpXGgoM0jigbnBHbojxfE/EUoxw== X-Google-Smtp-Source: ANB0VdYi5GSexV3AJsX2SqP5u75VrAJZV9CW49KolSzR6GvhU2cyHA2rGQA6PKUFM1vDmpl5vutfdLN0WE77e8VdErs= X-Received: by 2002:a5e:8347:: with SMTP id y7-v6mr45108iom.254.1536727211923; Tue, 11 Sep 2018 21:40:11 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Remko Popma Date: Wed, 12 Sep 2018 13:40:01 +0900 Message-ID: Subject: Re: [Bug] [2.5.2] groovy.cli.picocli.CliBuilder.parseFromSpec does not cast its result to the correct type To: dev@groovy.apache.org Content-Type: multipart/alternative; boundary="000000000000955cfd0575a52ff6" --000000000000955cfd0575a52ff6 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Kevin, that=E2=80=99s strange, there are working unit tests that do exactly= the same... For example: https://github.com/apache/groovy/blob/GROOVY_2_5_X/subprojects/groovy-cli-p= icocli/src/test/groovy/groovy/cli/picocli/CliBuilderTest.groovy#L794 On Wed, Sep 12, 2018 at 12:52 Kevin Perkins wrote: > Hello, > > I think I've found a bug with groovy.cli.picocli.CliBuilder as of Groovy > 2.5.2. I didn't find this particular issue in JIRA. I figured I'd ask her= e. > The parseFromSpec method of groovy.cli.picocli.CliBuilder seems to always > return a LinkedHashMap instead of the expected type (the class given as t= he > first argument). The source my IDE shows me for this method has "cliOptio= ns > as T" as the last line in the method. I think that the problem is T is > erased when the method is compiled and so the "as T" does (effectively) > nothing. I think the correct code would be > "cliOptions.asType(optionsClass)". > > Environment information: > /* -------------- groovy --version ------------------------------------ *= / > Groovy Version: 2.5.2 JVM: 1.8.0_172 Vendor: Oracle Corporation OS: > Windows 7 > > /* --------------- IDE version info ------------------------------------- > */ > IntelliJ IDEA 2018.2.3 (Ultimate Edition) > Build #IU-182.4323.46, built on September 3, 2018 > JRE: 1.8.0_152-release-1248-b8 amd64 > JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o > Windows 7 6.1 > > The following code demonstrates the issue: > /* ------------------------ Begin Example Code ------------------------ *= / > import groovy.cli.Option > import groovy.cli.picocli.CliBuilder > > class CliBuilderBug { > interface CliArguments { > @Option(longName=3D'dummy') int dummy() > } > > static void main(String[] args) { > CliBuilder builder =3D new CliBuilder() > > def ok =3D builder.parseFromSpec(CliArguments, args) as CliArgume= nts > assert ok instanceof CliArguments // ok > println "Using 'as' works." > > def notOk =3D builder.parseFromSpec(CliArguments, args) > assert notOk instanceof LinkedHashMap // this assertion is true > assert notOk instanceof CliArguments // fails > println 'We never get here.' > } > } > /* ------------------------ End Example Code ------------------------ */ > > I hope this is helpful, and thank you for your time. > - Kevin Perkins > NOTICE TO RECIPIENT: If you are not the intended recipient of this > e-mail, you are prohibited from sharing, copying, or otherwise using or > disclosing its contents. If you have received this e-mail in error, plea= se > notify the sender immediately by reply e-mail and permanently delete this > e-mail and any attachments without reading, forwarding or saving them. > Thank you. > > --000000000000955cfd0575a52ff6 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Kevin, that=E2=80=99s strange, there are working uni= t tests that do exactly the same...
For exampl= e:



On Wed, Sep 12, 201= 8 at 12:52 Kevin Perkins <Kevin.= Perkins@kp.org> wrote:
Hello= ,

I think I've found a bug with groovy.cli.picocli.CliBuilder as of Groov= y 2.5.2. I didn't find this particular issue in JIRA. I figured I'd= ask here. The parseFromSpec method of groovy.cli.picocli.CliBuilder seems = to always return a LinkedHashMap instead of the expected type (the class gi= ven as the first argument). The source my IDE shows me for this method has = "cliOptions as T" as the last line in the method. I think that th= e problem is T is erased when the method is compiled and so the "as T&= quot; does (effectively) nothing. I think the correct code would be "c= liOptions.asType(optionsClass)".

Environment information:
/* -------------- groovy --version ------------------------------------ */<= br> Groovy Version: 2.5.2 JVM: 1.8.0_172 Vendor: Oracle Corporation OS: Windows= 7

/* --------------- IDE version info ------------------------------------- *= /
IntelliJ IDEA 2018.2.3 (Ultimate Edition)
Build #IU-182.4323.46, built on September 3, 2018
JRE: 1.8.0_152-release-1248-b8 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 7 6.1

The following code demonstrates the issue:
/* ------------------------ Begin Example Code ------------------------ */<= br> import groovy.cli.Option
import groovy.cli.picocli.CliBuilder

class CliBuilderBug {
=C2=A0 =C2=A0 interface CliArguments {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 @Option(longName=3D'dummy') int dummy()=
=C2=A0 =C2=A0 }

=C2=A0 =C2=A0 static void main(String[] args) {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 CliBuilder builder =3D new CliBuilder()

=C2=A0 =C2=A0 =C2=A0 =C2=A0 def ok =3D builder.parseFromSpec(CliArguments, = args) as CliArguments
=C2=A0 =C2=A0 =C2=A0 =C2=A0 assert ok instanceof CliArguments // ok
=C2=A0 =C2=A0 =C2=A0 =C2=A0 println "Using 'as' works."
=C2=A0 =C2=A0 =C2=A0 =C2=A0 def notOk =3D builder.parseFromSpec(CliArgument= s, args)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 assert notOk instanceof LinkedHashMap // this a= ssertion is true
=C2=A0 =C2=A0 =C2=A0 =C2=A0 assert notOk instanceof CliArguments // fails =C2=A0 =C2=A0 =C2=A0 =C2=A0 println 'We never get here.'
=C2=A0 =C2=A0 }
}
/* ------------------------ End Example Code ------------------------ */
I hope this is helpful, and thank you for your time.
- Kevin Perkins
NOTICE TO RECIPIENT:=C2=A0 If you are not the intended recipient of this e-= mail, you are prohibited from sharing, copying, or otherwise using or discl= osing its contents.=C2=A0 If you have received this e-mail in error, please= notify the sender immediately by reply e-mail and permanently delete this = e-mail and any attachments without reading, forwarding or saving them.=C2= =A0 Thank you.

--000000000000955cfd0575a52ff6--