Bug with S2259 (undefined property - ReferenceError)

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension): Community Edition, Version 9.9 (build 65466)

  • how is SonarQube deployed: AWS EC2

  • Summary: If a property is declared on a json object, but undefined, sonar should detect the rule S2259, but doesn’t, if the json object is used within a function which calls the undefined property, there’s an error which sonar should have detected.

const testObject = {
    foo: "bar",
    marco: "polo",
    arg1,
};

function test(object) {
    let a = b + object.arg1
    console.log(a)
}

test(testObject)

1 Like

Hello @a8trejo,

In the code example you provided, where would you expect an issue to be raised?

In the code example, the current analyzer engine cannot detect that object.arg1 is the property defined at line 4 for the global testObject variable.

Best,
Ilia

Hello @ilia ! sorry for the delay, I was hoping Sonar would mark line 4 as a S2259 bug

I also realized there’s an extra bug on the small snippet, it should have also pointed out in line 8 the variable b as another bug of undefined variable.

Hello @a8trejo,

The analyzer does not support cross-file analysis, therefore we won’t raise an issue for variables that were not declared inside the file. They might be global.

Best,
Ilia

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.