Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 7D434200C1D for ; Thu, 2 Feb 2017 00:19:15 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 7C186160B69; Wed, 1 Feb 2017 23:19:15 +0000 (UTC) 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 942C1160B6A for ; Thu, 2 Feb 2017 00:19:14 +0100 (CET) Received: (qmail 12534 invoked by uid 500); 1 Feb 2017 23:19:13 -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 12520 invoked by uid 99); 1 Feb 2017 23:19:13 -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; Wed, 01 Feb 2017 23:19:13 +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 35ED1C1013 for ; Wed, 1 Feb 2017 23:19:13 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -1.999 X-Spam-Level: X-Spam-Status: No, score=-1.999 tagged_above=-999 required=6.31 tests=[KAM_LAZY_DOMAIN_SECURITY=1, RP_MATCHES_RCVD=-2.999] autolearn=disabled 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 kV0QeyGUxSR3 for ; Wed, 1 Feb 2017 23:19:12 +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 B228C61F0D for ; Wed, 1 Feb 2017 23:19:10 +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 965E9E08C3 for ; Wed, 1 Feb 2017 23:19:05 +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 7806725292 for ; Wed, 1 Feb 2017 23:19:05 +0000 (UTC) Date: Wed, 1 Feb 2017 23:19:05 +0000 (UTC) From: "Paul King (JIRA)" To: notifications@groovy.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Closed] (GROOVY-6764) Problem Referring To Statically Imported Constants MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Wed, 01 Feb 2017 23:19:15 -0000 [ https://issues.apache.org/jira/browse/GROOVY-6764?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Paul King closed GROOVY-6764. ----------------------------- > Problem Referring To Statically Imported Constants > -------------------------------------------------- > > Key: GROOVY-6764 > URL: https://issues.apache.org/jira/browse/GROOVY-6764 > Project: Groovy > Issue Type: Bug > Affects Versions: 2.1.9, 2.4.0-rc-1 > Reporter: Jeff Brown > Assignee: Paul King > Fix For: 2.4.8 > > Attachments: constantsquestion.zip > > > It appears that if a class implements an interface which declares constants, Groovy code which statically imports the constant from the class (not the interface) doesn't work. I think this is supposed to work. It does work from Java. See the attached app in constantsquestion.zip which includes the following code. Extract the .zip and run "./gradlew test" to see that the Java test passes and the Groovy test fails. > {code:borderStyle=solid|title=src/main/java/com/demo/Constants.java} > package com.demo; > public interface Constants { > int ANSWER = 42; > } > {code} > {code:borderStyle=solid|title=src/main/java/com/demo/Helper.java} > package com.demo; > public class Helper implements Constants { > } > {code} > {code:borderStyle=solid|title=test/java/com/demo/JavaHelperTests.java} > package com.demo; > import org.junit.Test; > import org.junit.runner.RunWith; > import org.junit.runners.JUnit4; > import static org.junit.Assert.assertEquals; > import static com.demo.Helper.ANSWER; > @RunWith(JUnit4.class) > public class JavaHelperTests { > @Test > public void testAccessingConstant() { > // this test passes... > assertEquals(42, ANSWER); > } > } > {code} > {code:borderStyle=solid|title=test/groovy/com/demo/GroovyHelperSpec.groovy} > package com.demo > import spock.lang.Specification > import static com.demo.Helper.ANSWER > class GroovyHelperSpec extends Specification { > void 'test referring to statically imported constant'() { > // this test fails... > expect: > 42 == ANSWER > } > } > {code} > The error message from the Groovy spec is: > {noformat} > groovy.lang.MissingPropertyException: No such property: ANSWER for class: com.demo.GroovyHelperSpec > at com.demo.GroovyHelperSpec.test referring to statically imported constant(GroovyHelperSpec.groovy:10) > {noformat} > Note that everything works fine from Groovy if the constant is imported from the interface instead of from the class which implements the interface. > Is this a bug? -- This message was sent by Atlassian JIRA (v6.3.15#6346)