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

[jira] [Updated] (GROOVY-8585) too many accessedVariable

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

Daniel Sun updated GROOVY-8585:
-------------------------------
    Description: 
VariableExpression `str`  has endless accessedVariable, i.e. accessedVariable -> accessedVariable -> ... -> accessedVariable -> ...

{code:java}
            def x() {
                String str = 'hello'
            }
{code}

VariableExpression Snippet
{code:java}
    public void setAccessedVariable(Variable origin) {
        checkVariable(origin);
        this.accessedVariable = origin;
    }

// the code added just for check
public static boolean checkVariable(Variable origin) {
        if (!(origin instanceof VariableExpression)) {
            return false;
        }

        int cnt = 0;
        for (VariableExpression ve = (VariableExpression) origin; ve != null; ve = (VariableExpression) ve.getAccessedVariable()) {
            cnt++;

            if (cnt > 1000) {
                throw new RuntimeException("too many accessedVariable");
            }
        }

        return false;
    }
{code}



  was:
VariableExpression `str`  has endless accessedVariable, i.e. accessedVariable -> accessedVariable -> ... -> accessedVariable -> ...

{code:java}
        class Foo {
            def bar() {
                Object str = new Object()
                str = "str"
                str.toUpperCase() // here compile error
            }
        }
        println 123
{code}

VariableExpression Snippet
{code:java}
    public void setAccessedVariable(Variable origin) {
        checkVariable(origin);
        this.accessedVariable = origin;
    }

// the code added just for check
public static boolean checkVariable(Variable origin) {
        if (!(origin instanceof VariableExpression)) {
            return false;
        }

        int cnt = 0;
        for (VariableExpression ve = (VariableExpression) origin; ve != null; ve = (VariableExpression) ve.getAccessedVariable()) {
            cnt++;

            if (cnt > 100) {
                throw new RuntimeException("too many accessedVariable");
            }
        }

        return false;
    }
{code}




> too many accessedVariable
> -------------------------
>
>                 Key: GROOVY-8585
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8585
>             Project: Groovy
>          Issue Type: Bug
>            Reporter: Daniel Sun
>            Priority: Critical
>
> VariableExpression `str`  has endless accessedVariable, i.e. accessedVariable -> accessedVariable -> ... -> accessedVariable -> ...
> {code:java}
>             def x() {
>                 String str = 'hello'
>             }
> {code}
> VariableExpression Snippet
> {code:java}
>     public void setAccessedVariable(Variable origin) {
>         checkVariable(origin);
>         this.accessedVariable = origin;
>     }
> // the code added just for check
> public static boolean checkVariable(Variable origin) {
>         if (!(origin instanceof VariableExpression)) {
>             return false;
>         }
>         int cnt = 0;
>         for (VariableExpression ve = (VariableExpression) origin; ve != null; ve = (VariableExpression) ve.getAccessedVariable()) {
>             cnt++;
>             if (cnt > 1000) {
>                 throw new RuntimeException("too many accessedVariable");
>             }
>         }
>         return false;
>     }
> {code}



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