You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Shil Sinha (JIRA)" <ji...@apache.org> on 2016/02/25 06:51:18 UTC
[jira] [Resolved] (GROOVY-7312) Compiler generates invalid inner
class constructor
[ https://issues.apache.org/jira/browse/GROOVY-7312?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Shil Sinha resolved GROOVY-7312.
--------------------------------
Resolution: Fixed
Fix Version/s: 2.4.7
> Compiler generates invalid inner class constructor
> --------------------------------------------------
>
> Key: GROOVY-7312
> URL: https://issues.apache.org/jira/browse/GROOVY-7312
> Project: Groovy
> Issue Type: Bug
> Components: class generator, Compiler
> Affects Versions: 2.4.0
> Reporter: Adam Lewandowski
> Assignee: Shil Sinha
> Priority: Minor
> Fix For: 2.4.7
>
>
> replacement description:
> {code:title=Intf.groovy|borderStyle=solid}
> interface Intf {
> def foo = { "bar" }
> }
> {code}
> Will create an inner class that lacks the static modifier for the inner class table. Compare with
> {code:title=JavaInterface.java}
> public interface JavaInterface {
> class NestedInInterface {}
> }
> {code}for reference
> Original description:
> The JLS specifies that an implicitly-declared constructor of a non-private inner class "implicitly declares one formal parameter representing the immediately enclosing instance of the class" ([Section 8.8.9|http://docs.oracle.com/javase/specs/jls/se8/html/jls-8.html#jls-8.8.9], see also [8.8.1|http://docs.oracle.com/javase/specs/jls/se8/html/jls-8.html#jls-8.8.1]).
> {code:title=Intf.groovy|borderStyle=solid}
> interface Intf {
> def foo = { "bar" }
> }
> {code}
> The above code creates an inner class (Intf$1, not exactly sure what it's for) with a default constructor that has no parameters:
> {noformat}
> $ javap -p -classpath classes 'Intf$1'
> Compiled from "Intf.groovy"
> class Intf$1 implements groovy.lang.GroovyObject {
> ...
> public Intf$1();
> ...
> }
> {noformat}
> While not a major issue, this non-conformance can break interoperability with anything that expects to work with Java classes. This particular example came up while trying to use a similarly-declared Groovy class from a Scala class, where the Scala compiler was unable to parse the generated inner class.
> For reference, here is an example Java Inner class and it's compiled representation. Note the constructor parameter on the inner class.
> {code:title=JavaObj.java|borderStyle=solid}
> public class JavaObj {
> public class Inner {}
> }
> {code}
> {noformat}
> $ javap -p -classpath classes 'JavaObj$Inner'
> public class JavaObj$Inner {
> final JavaObj this$0;
> public JavaObj$Inner(JavaObj);
> }
> {noformat}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)