You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Anton Pryamostanov (JIRA)" <ji...@apache.org> on 2018/11/18 18:14:00 UTC

[jira] [Created] (GROOVY-8891) Trait Instance Init Block causes Runtime exception for Trait fields with default values

Anton Pryamostanov created GROOVY-8891:
------------------------------------------

             Summary: 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


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}
{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.



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