sonar-openedge icon indicating copy to clipboard operation
sonar-openedge copied to clipboard

Rule idea: Setter should assign value locally

Open ccecvb opened this issue 5 months ago • 0 comments

When reading

https://community.progress.com/s/article/4GL-ABL-Setting-a-property-as-an-output-parameter-inside-the-setter-block-causes-a-STOP-condition-and-the-client-crashes?popup=true

I thought this would be a good idea for a rule.

I reduced the attached sample code to a single failing class.

class IndefiniteSetter:

    def public property a as longchar no-undo
    get.
    set (avalue as longchar):
        Normalize(input avalue, output a). // endless loop here because a is used as output
    end set.

    method private void Normalize(input ivalue as longchar, output oresult as longchar):
            oresult = ivalue.
    end.

    constructor public IndefiniteSetter():
        a = "Set"    .

    end.

end class.

fix : Use an intermediate variable

    def public property a as longchar no-undo
    get.
    set (avalue as longchar):
        define variable lresult as longchar no-undo.
        Normalize(input avalue, output lresult).
        a = lres.
    end set.

ccecvb avatar Sep 03 '24 13:09 ccecvb