Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Won't Fix
-
2.5.5
-
None
-
None
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:
trait Trait { Integer fieldWithDefaultValue = 0 { System.out.println("Only instance init block gives this problem") } } class ClassWithTrait implements Trait { } new ClassWithTrait().fieldWithDefaultValue
Runtime exception:
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)
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.
Attachments
Issue Links
- is related to
-
GROOVY-8892 Trait instance init blocks are called only when there are fields defined in same Trait
- Closed
- relates to
-
GROOVY-8880 Traits - static/instance init blocks
- Closed