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 AD0001 in S138: NullReferenceException #7134

Closed
Tim-Pohlmann opened this issue Apr 27, 2023 · 1 comment · Fixed by #7155
Closed

Fix AD0001 in S138: NullReferenceException #7134

Tim-Pohlmann opened this issue Apr 27, 2023 · 1 comment · Fixed by #7155
Assignees
Labels
Area: C# C# rules related issues. Type: Bug Exceptions and blocking issues during analysis.
Milestone

Comments

@Tim-Pohlmann
Copy link
Contributor

Description

The error appears in the project JellyFin, which I recently added to peachee-dotnet.

CSC : error AD0001: Analyzer 'SonarAnalyzer.Rules.CSharp.MethodsShouldNotHaveTooManyLines' threw an exception of type 'System.NullReferenceException' with message 'Object reference not set to an instance of an object.'. [C:\Project\Jellyfin.Server\Jellyfin.Server.csproj]

Repro steps

JellyFin GitHub: https://github.com/jellyfin/jellyfin
Error Log: https://cirrus-ci.com/task/4552322081095680?logs=build#L2576
Peach configuration: https://github.com/SonarSource/peachee-dotnet/blob/b8a849c086699dfb1ec9340a26eaef1ac1e636b6/.cirrus.yml#L258-L259

Related information

  • .NET 6
@Tim-Pohlmann Tim-Pohlmann added Type: Bug Exceptions and blocking issues during analysis. Area: C# C# rules related issues. labels Apr 27, 2023
@pavel-mikula-sonarsource pavel-mikula-sonarsource added this to the 9.1 milestone Apr 27, 2023
@Tim-Pohlmann Tim-Pohlmann changed the title AD0001 in S103: NullReferenceException Fix AD0001 in S103: NullReferenceException Apr 27, 2023
@antonioaversa
Copy link
Contributor

antonioaversa commented May 1, 2023

The exception is produced in

private static IEnumerable<SyntaxToken> GetMethodTokens(LocalFunctionStatementSyntaxWrapper wrapper) =>
    wrapper.ExpressionBody?.Expression.DescendantTokens()
    ?? wrapper.Body.Statements.SelectMany(s => s.DescendantTokens());

Due to Body being null, in presence of extern local functions, which don't have body.

#pragma warning disable SA1300 // Entrypoint is case sensitive.
[DllImport("libc")]
static extern int chmod(string pathname, int mode);
#pragma warning restore SA1300

Example in .\Jellyfin.Server\Program.cs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: C# C# rules related issues. Type: Bug Exceptions and blocking issues during analysis.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants