Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LC0068 - False Negative RecordRef #755

Open
pri-kise opened this issue Aug 29, 2024 · 2 comments
Open

LC0068 - False Negative RecordRef #755

pri-kise opened this issue Aug 29, 2024 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@pri-kise
Copy link

I know that it's difficult to check this rule for RecordRef, but there is one case, that maybe can be found.

local procedure DoMagic(Entry: Record "PTE Entry"; )
var
    IncomingDocument: Record "Incoming Document";
    RecRef: RecordRef;
begin
    if Entry."Record ID".TableNo() <> Database::"Incoming Document" then
        exit;

    RecRef.Open(Database::"Incoming Document"); 
    if CompanyName() <> Entry."Company Name" then begin
        RecRef.ChangeCompany(Entry."Company Name");
        IncomingDocument.ChangeCompany(Entry."Company Name");
    end;
    if not RecRef.Get(Entry."Record ID") then //missing warning
        exit;
    RecRef.SetTable(IncomingDocument);
    //more Magic
end;

At the least the indirect read permission could be found here.

@StefanMaron StefanMaron self-assigned this Sep 3, 2024
@StefanMaron StefanMaron added the bug Something isn't working label Sep 3, 2024
@StefanMaron
Copy link
Owner

I dont see any option to see what table the reocrdref is pointing at, maybe @Arthurvdv has an idea?

@Arthurvdv
Copy link
Collaborator

This is a tough one, not impossible I believe, but could be complex.

The assignment of the table on the RecordRef is determined during runtime. So the LinterCop, as a static code analyzer, can’t determine this during compile time.

What I can think of is something similar as the CodeCop AA0181 warning. This would then translate to;

image

  1. Trigger on a .Get() of a RecordRef instance
  2. Retrieving the Local/Global variable instance
  3. Loop through the codeblock of the method, line-by-line, for a match on .Open()
  4. Retrieve the Database:: value

Then there could be more complex situations:

local procedure DoMagic(Entry: Record "PTE Entry")
var
    RecRef: RecordRef;
begin
    RecRef.Open(Database::"Incoming Document");
    RecRef.Get(Entry."Record ID");

    RecRef.Open(Database::"Document Sharing");
    RecRef.Get(Entry."Record ID");
    RecRef.Modify(false)
end;

The .Modify() here could then raise a false positive for the "Incoming Document" table. So when looping through the codeblock, we need to start at the line of the action (.Get/.Modify) and walk upwards till we find the first matching .Open() reference.

With the restriction that the .Open operator and .Get/.Modift/.. operator are within in the same procedure I think it should be possible. I'm unsure if there are other scenario's where the "just-look-at-the-lines-above-in-the-code" method could still cause false positives.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants