microsoft / AL

Home of the Dynamics 365 Business Central AL Language extension for Visual Studio Code. Used to track issues regarding the latest version of the AL compiler and developer tools available in the Visual Studio Code Marketplace or as part of the AL Developer Preview builds for Dynamics 365 Business Central.
MIT License
732 stars 243 forks source link

[AA0175] ISEMPTY is not an appropriate substitute. #5631

Closed rdebath closed 4 years ago

rdebath commented 4 years ago

Describe the bug Incorrect complaint as variable is used: Variable 'Json' queries the database in 'UpdateNAVRecord' but does not use the queried record. Only find or get record if you need to access the values. Consider using ISEMPTY.

To Reproduce Steps and to reproduce the behavior:

  1. Put it in a codeunit

AL Code to reproduce the issue

    procedure UpdateNAVRecord(JsonStr: Text)
    var
        Json: Record "JSON Buffer" temporary;
        Lastentry: Integer;
        Ind: Text;
    begin
        Json.ReadFromText(JsonStr);

        Json.Reset;
        Json.SetRange(Depth, 0);
        Json.SetRange("Token type", Json."Token type"::"Start Array");
        if not Json.FindFirst then Error('JSON data must begin with [{');
        Json.Reset;
        Json.SetRange(Depth, 1);
        Json.SetRange("Token type", Json."Token type"::"Start Object");
        if not Json.FindFirst then Error('JSON data must begin with [{');

        repeat
            Lastentry := Json."Entry No.";
            Ind := Json.Path;
            if Ind <> '' then Ind := Ind + '.';

            Json.Reset;
            Json.SetRange(Depth, 2);
            Json.SetFilter("Token type", '<>%1', Json."Token type"::"Property Name");
            Json.SetRange(Path, Ind + 'command');
            if not Json.FindFirst then Error('Each JSON object in the array must have a "command" property');
            EvaluateCommand(Json.Value);

            Json.Reset;
            Json.SetRange(Depth, 1);
            Json.SetRange("Token type", Json."Token type"::"Start Object");
            Json.SetFilter("Entry No.", '>%1', Lastentry);
        until not Json.FindFirst;
    end;

    procedure EvaluateCommand(JsonStr: Text)
    begin

    end;

Expected behavior Silence because the contents of the Json.Findfirst is used at the start of the next loop.

Screenshots image

If applicable, add screenshots to help explain your problem.

5. Versions: Name: AL Language Id: ms-dynamics-smb.al Description: AL development tools for Dynamics 365 Business Central Version: 5.0.219300 Publisher: Microsoft VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=ms-dynamics-smb.al

MarcHansenMicrosoft commented 4 years ago

Fixed in master