groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (GROOVY-8360) Enums that are nested classes do not have the static modifier set
Date Tue, 24 Oct 2017 01:19:00 GMT

    [ https://issues.apache.org/jira/browse/GROOVY-8360?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16216167#comment-16216167
] 

ASF GitHub Bot commented on GROOVY-8360:
----------------------------------------

Github user shils commented on a diff in the pull request:

    https://github.com/apache/groovy/pull/619#discussion_r146433436
  
    --- Diff: src/test/gls/enums/EnumTest.groovy ---
    @@ -592,6 +592,80 @@ class EnumTest extends CompilableTestSupport {
                 assert UsState.ID.toString() == 'Idaho'
             '''
         }
    +
    +    void testNestedEnumHasStaticModifier_GROOVY_8360() {
    +        assertScript '''
    +            class Foo {
    +                enum Bar {
    +                    X('x'), Y
    +                    String s
    +                    Bar(String s) { this.s = s }
    +                    Bar() {}
    +                }
    +            }            
    +            assert java.lang.reflect.Modifier.isStatic(Foo.Bar.modifiers)
    +            assert Foo.Bar.X.s == 'x'
    +        '''
    +    }
    +
    +    void testEnumWithinInnerClassHasStaticModifier_GROOVY_8360() {
    +        assertScript '''
    +            class Foo {
    +                class Baz {
    +                    enum Bar {
    +                        X('x'), Y                                                   
                    
    +                        String s                                                    
                                           
    +                        Bar(String s) { this.s = s }
    +                        Bar() {}                                                
    +                    }                
    +                }
    +            }            
    +            assert java.lang.reflect.Modifier.isStatic(Foo.Baz.Bar.modifiers)
    +            assert Foo.Baz.Bar.X.s == 'x'
    +        '''
    +    }
    +
    +    void testNestedEnumHasStaticModifierSC_GROOVY_8360() {
    +        assertScript '''
    +            @groovy.transform.CompileStatic
    +            class Foo {
    +                enum Bar {
    +                    X('x'), Y
    +                    String s
    +                    Bar(String s) { this.s = s }
    +                    Bar() {}
    +                }
    +            }          
    +            @groovy.transform.CompileStatic
    +            void test() {
    +                assert java.lang.reflect.Modifier.isStatic(Foo.Bar.getModifiers())
    --- End diff --
    
    Unrelated to this issue - property style getter calls on Enum classes throw NoSuchFieldErrors
at runtime when statically compiled.


> Enums that are nested classes do not have the static modifier set
> -----------------------------------------------------------------
>
>                 Key: GROOVY-8360
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8360
>             Project: Groovy
>          Issue Type: Bug
>          Components: Compiler
>    Affects Versions: 3.x, 2.6.0-alpha-1, 2.4.12, 2.5.0-beta-2
>            Reporter: Shil Sinha
>
> In java, enums that are nested classes have the static modifier set i.e. if Bar is an
enum defined within a class Foo, {{assert Modifier.isStatic(Foo.Bar.modifiers)}} passes. The
assertion does not hold if Foo and Bar are defined in groovy:
> {code}
> class Foo {
>     enum Bar {
>         X
>     }
> }
>             
> assert java.lang.reflect.Modifier.isStatic(Foo.Bar.modifiers)
> {code}
> This can be problematic in cases like https://mongodb.github.io/morphia/, where the type
of a mapped field cannot be a non-static inner class. Of course that library could also be
more enum-aware when validating mapped fields, but that's a separate issue. 
> A simple workaround for this issue is to explicitly declare the enum as static, so it's
not critical that a patch for this be in 2.4.X if it's considered a breaking change (though
no tests fail with the change.)



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Mime
View raw message