groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "jacob shnaidman (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (GROOVY-8398) Overriding getProperty makes getAttribute throw missing property exception
Date Fri, 01 Dec 2017 21:24:00 GMT

     [ https://issues.apache.org/jira/browse/GROOVY-8398?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

jacob shnaidman updated GROOVY-8398:
------------------------------------
    Description: 
The following code fails in two unexpected ways:

{code:java}
class PropClass {
    String myString = 'groovyClass'
    String otherProp = 'other Property'

    void myMethod() {
        //do nothing
    }

    void registerMethod(Closure closure) {
        this.metaClass.myMethod = closure
    }

    def getProperty(String name) {
        if (name == 'otherProp')
            //forward the request to getter
            return metaClass.getProperty(this, name)
        else if (name == 'myString') {
            return 'myString'
        }
        else
            return "new var $name"
    }
}

PropClass properties = new PropClass()

//this shouldn't fail
GroovyAssert.shouldFail {
    println properties.metaClass.getAttribute(properties, 'myString')
}
// and this shouldn't fail
properties.registerMethod { ->
    println 'this fails'    
}
{code}

This happens whenever you override getProperty


  was:
The following code fails in two unexpected ways:

{code:java}
class PropClass {
    String myString = 'groovyClass'
    String otherProp = 'other Property'

    void myMethod() {
        //do nothing
    }

    void registerMethod(Closure closure) {
        this.metaClass.myMethod = closure
    }

    def getProperty(String name) {
        if (name == 'otherProp')
            //forward the request to getter
            return metaClass.getProperty(this, name)
        else if (name == 'myString') {
            return 'myString'
        }
        else
            return "new var $name"
    }
}

PropClass properties = new PropClass()

//this shouldn't fail
GroovyAssert.shouldFail {
    println properties.metaClass.getAttribute(properties, 'myString')
}
// and this shouldn't fail
properties.registerMethod { ->
    println 'this fails'    
}
{code}

This happens whenever you override getProperties



> Overriding getProperty makes getAttribute throw missing property exception
> --------------------------------------------------------------------------
>
>                 Key: GROOVY-8398
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8398
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 2.4.12
>         Environment: Ubuntu
>            Reporter: jacob shnaidman
>
> The following code fails in two unexpected ways:
> {code:java}
> class PropClass {
>     String myString = 'groovyClass'
>     String otherProp = 'other Property'
>     void myMethod() {
>         //do nothing
>     }
>     void registerMethod(Closure closure) {
>         this.metaClass.myMethod = closure
>     }
>     def getProperty(String name) {
>         if (name == 'otherProp')
>             //forward the request to getter
>             return metaClass.getProperty(this, name)
>         else if (name == 'myString') {
>             return 'myString'
>         }
>         else
>             return "new var $name"
>     }
> }
> PropClass properties = new PropClass()
> //this shouldn't fail
> GroovyAssert.shouldFail {
>     println properties.metaClass.getAttribute(properties, 'myString')
> }
> // and this shouldn't fail
> properties.registerMethod { ->
>     println 'this fails'    
> }
> {code}
> This happens whenever you override getProperty



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

Mime
View raw message