Identify NPE in typescript/JS

Hi, we are using SonarQube 9.2.3, and one of our projects is asking if there is a possibility to identify Null Pointer issues in TS/JS. They took over an older project and regularly face null pointer issues in a way like:

const element = this.getView().getRecord();

where “getView()” might return a NULL value, hence failing the code if it does. They have lots of such chained calls in that project and having lots of issues with missing NULL checks there.

SonarQube so far does not help to identify these, is there any way, how it could assist here?

Hello Ralf,

Thank you for your feedback!

The JavaScript/TypeScript analyser already provides a rule, namely S2259, to identify null pointer issues. However, the current implementation limits itself to target objects that are identifiers only. Therefore, it won’t be able to report an issue on the snippet you shared.

Nevertheless, this is a good opportunity to extend the scope of the rule and identify null pointer issues on patterns like the one you highlighted. In this regard, I created the following ticket to improve the rule as soon as possible.


1 Like

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