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

Fix S3928: Rule should not throw NullReferenceException for ArgumentNullException with null parameter name #1867

Closed
nwoolls opened this issue Sep 19, 2018 · 1 comment
Assignees
Labels
Type: Bug Exceptions and blocking issues during analysis.
Milestone

Comments

@nwoolls
Copy link

nwoolls commented Sep 19, 2018

Description

Running the SonarScanner on an .NET Core project that passes null to the ArgumentNullException constructor results in a NullReferenceException being logged by CSC.

Repro steps

From a *nix environment:

  1. Run mkdir sonar-csharp-AD0001
  2. Run cd sonar-csharp-AD0001
  3. Run dotnet new console
  4. Edit the generated .csproj file and specify a ProjectGuid
  5. Edit the generated Program.cs and add throw new ArgumentNullException(null, String.Empty);
  6. Run dotnet <path-to-scanner> begin [args]
  7. Run dotnet build
  8. Run dotnet <path-to-scanner> end [args]

Expected behavior

No warnings logged by CSC.

Actual behavior

The following warning is found in the logs:

CSC : warning AD0001: Analyzer 'SonarAnalyzer.Rules.CSharp.CheckArgumentException' threw an exception of type 'System.NullReferenceException' with message 'Object reference not set to an instance of an object.'. [/Users/jdoe/src/tmp/sonar-csharp-AD0001/sonar-csharp-AD0001.csproj]

Known workarounds

Don't pass null to ArgumentNullException, but this should probably be a rule not a difficult to track down NullReferenceException.

Related information

  • SonarC# Version: 7.5 (build 6605)
  • SonarScanner Version: 4.3.1
  • SonarQube Version: 6.7.1 (build 35068)
  • .NET Core SDK Version: 2.1.402
  • MSBuild Version: 15.4.0.0
@Evangelink Evangelink self-assigned this Sep 24, 2018
@Evangelink Evangelink added Type: Bug Exceptions and blocking issues during analysis. Area: Rules labels Sep 24, 2018
@Evangelink Evangelink added this to the 7.6 milestone Sep 24, 2018
@Evangelink
Copy link
Contributor

Hi @nwoolls,

Thanks for raising this issue!
It will be fixed on the next release.

Cheers,
Amaury

@Evangelink Evangelink changed the title AD0001 warning for NullReferenceException issued scanning "bad" ArgumentNullException code Fix S3928: Rule should not throw NullReferenceException for ArgumentNullException with null parameter name Sep 24, 2018
@ghost ghost added the Status: Needs Review label Sep 24, 2018
@ghost ghost removed the Status: Needs Review label Sep 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Exceptions and blocking issues during analysis.
Projects
None yet
Development

No branches or pull requests

2 participants