[ https://issues.apache.org/jira/browse/GROOVY-8891?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Anton Pryamostanov updated GROOVY-8891: --------------------------------------- Description: 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. was: 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. However Please see issue (TBD) which can mask this problem from appearing in Static Init Block also. > 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)