groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Anton Pryamostanov (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (GROOVY-8891) Trait Instance Init Block causes Runtime exception for Trait fields with default values
Date Sun, 18 Nov 2018 18:23:01 GMT

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

Anton Pryamostanov commented on GROOVY-8891:
--------------------------------------------

[~paulk] FYI kindly


> Trait Instance Init Block causes Runtime exception for Trait fields with default values
> ---------------------------------------------------------------------------------------
>
>                 Key: GROOVY-8891
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8891
>             Project: Groovy
>          Issue Type: Bug
>          Components: Compiler, groovy-runtime
>    Affects Versions: 2.5.5
>            Reporter: Anton Pryamostanov
>            Priority: Major
>
> With ref. to GROOVY-8880, when instance or static field has default value in Trait, when
same Trait has Instance Init Block, Runtime exception happens.
> Example code:
> {code}
> trait Trait {
>     Integer fieldWithDefaultValue = 0
>     {
>         System.out.println("Only instance init block gives this problem")
>     }
> }
> class ClassWithTrait implements Trait {
> }
> new ClassWithTrait().fieldWithDefaultValue
> {code}
> Runtime exception:
> {code}
> groovy.lang.MissingMethodException: No signature of method: java.lang.Integer.call()
is applicable for argument types: (Trait$Trait$Helper$__init__closure1) values: [Trait$Trait$Helper$__init__closure1@5833d058]
> Possible solutions: wait(), abs(), any(), wait(long), each(groovy.lang.Closure), any(groovy.lang.Closure)
> 	at Trait$Trait$Helper.$init$(ConsoleScript80:3)
> 	at ClassWithTrait.<init>(ConsoleScript80)
> 	at ConsoleScript80.run(ConsoleScript80:9)
> {code}
> Note: It does not matter if field is static of instance.
> Note 2: Static Init Block in Trait does not cause same issue and works Ok.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message