microsoft / infersharp

Infer# is an interprocedural and scalable static code analyzer for C#. Via the capabilities of Facebook's Infer, this tool detects null dereferences, resource leaks, and thread-safety violations. It also performs taint flow tracking to detect critical security vulnerabilities like SQL injections.
MIT License
730 stars 29 forks source link

Doesn't recognise "throw helpers", such as `ArgumentNullException.ThrowIfNull` #90

Open cocowalla opened 2 years ago

cocowalla commented 2 years ago

.NET 6 introduced a bunch of new throw helpers - syntactic sugar for argument null checks.

Infer# doesn't seem to recognise how these work, and will show Null Dereference errors even though the argument cannot be null because ArgumentNullException.ThrowIfNull has been used. I've verified that switching back to the old way works:

if (myArg == null) throw new ArgumentNullException(nameof(myArg ));
matjin commented 2 years ago

Thanks for posting! This is a library method for which we don't have a model. We are updating the null dereference analysis backend in the next major release, and as part of that I'll be creating models for such methods. Will follow up on this.