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 3D926200C15 for ; Wed, 8 Feb 2017 16:43:48 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 3C3AD160B5A; Wed, 8 Feb 2017 15:43:48 +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 86B50160B4E for ; Wed, 8 Feb 2017 16:43:47 +0100 (CET) Received: (qmail 70290 invoked by uid 500); 8 Feb 2017 15:43:46 -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 70281 invoked by uid 99); 8 Feb 2017 15:43:46 -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; Wed, 08 Feb 2017 15:43:46 +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 5BBCE1A0150 for ; Wed, 8 Feb 2017 15:43:46 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -1.199 X-Spam-Level: X-Spam-Status: No, score=-1.199 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RP_MATCHES_RCVD=-2.999] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id WF7oJmAS5C5A for ; Wed, 8 Feb 2017 15:43:45 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTP id 914905FB73 for ; Wed, 8 Feb 2017 15:43:44 +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 8BB6BE031F for ; Wed, 8 Feb 2017 15:43:43 +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 AA00E2528B for ; Wed, 8 Feb 2017 15:43:42 +0000 (UTC) Date: Wed, 8 Feb 2017 15:43:42 +0000 (UTC) From: =?utf-8?Q?Peter_Myr=C3=A9n_=28JIRA=29?= To: notifications@groovy.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Comment Edited] (GROOVY-5728) Accessing private constructor from a static factory MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Wed, 08 Feb 2017 15:43:48 -0000 [ https://issues.apache.org/jira/browse/GROOVY-5728?page=3Dcom.atlassia= n.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=3D158= 57927#comment-15857927 ]=20 Peter Myr=C3=A9n edited comment on GROOVY-5728 at 2/8/17 3:43 PM: ------------------------------------------------------------- Same problem with static nested class. {code} public abstract class FooMain { private FooMain() {} public abstract String bar(); public static FooMain factory() { return new FooMainNested(); } public static void main(String[] args) { System.out.println(factory().bar()); } =20 private static class FooMainNested extends FooMain{ public String bar() { return "xxx"; } } } {code} This is expected, since nested static classes can't access private variable= s and methods. But, this also fails: {code} public class FooMain { private FooMain() {} public String bar(){return null;} public static FooMain factory() { return new FooMainNested(new FooMain()); }; public static void main(String[] args) { System.out.println(factory().bar()); } private class FooMainNested extends FooMain{ @Override public String bar() { return "xxx"; } } } {code} It woks with protected constructor though. {code} public abstract class FooMain { protected FooMain() {} public abstract String bar(); public static FooMain factory() { return new FooMain() { public String bar() { return "xxx"; } }; } =20 public static void main(String[] args) { System.out.println(factory().bar()); } =20 } {code} Tested with groovy 2.4.8 was (Author: petermyren): Same problem with static nested class. {code} public abstract class FooMain { private FooMain() {} public abstract String bar(); public static FooMain factory() { return new FooMainNested(); } public static void main(String[] args) { System.out.println(factory().bar()); } =20 private static class FooMainNested extends FooMain{ public String bar() { return "xxx"; } } } {code} It woks with protected constructor though. {code} public abstract class FooMain { protected FooMain() {} public abstract String bar(); public static FooMain factory() { return new FooMain() { public String bar() { return "xxx"; } }; } =20 public static void main(String[] args) { System.out.println(factory().bar()); } =20 } {code} Tested with groovy 2.4.8 > Accessing private constructor from a static factory > --------------------------------------------------- > > Key: GROOVY-5728 > URL: https://issues.apache.org/jira/browse/GROOVY-5728 > Project: Groovy > Issue Type: Bug > Components: groovy-runtime > Affects Versions: 2.0.4, 2.4.0-beta-3 > Reporter: Paul King > Priority: Minor > > The following code works fine from Java but fails in Groovy: > {code} > public abstract class FooMain { > private FooMain() {} > public abstract String bar(); > public static FooMain factory() { > return new FooMain() { > public String bar() { return "xxx"; } > }; > } > public static void main(String[] args) { > System.out.println(factory().bar()); > } > } > // =3D> java.lang.IllegalAccessError: tried to access method FooMain.()V from class FooMain$1 > {code} -- This message was sent by Atlassian JIRA (v6.3.15#6346)