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 S3878 FP: Jagged arrays #8163

Closed
ThorstenReichert opened this issue Oct 9, 2023 · 2 comments · Fixed by #9102
Closed

Fix S3878 FP: Jagged arrays #8163

ThorstenReichert opened this issue Oct 9, 2023 · 2 comments · Fixed by #9102
Assignees
Labels
Area: C# C# rules related issues. Area: VB.NET VB.NET rules related issues. Sprint: Hardening Fix FPs/FNs/improvements Type: False Positive Rule IS triggered when it shouldn't be.
Projects
Milestone

Comments

@ThorstenReichert
Copy link
Contributor

ThorstenReichert commented Oct 9, 2023

Description

When a C# method has an array of arrays as params parameter, S3878 is raised when the method is called. e.g. for

public class Repro8163
{
    public static void Method(params object[][] array) { }

    public static void CallParamsMethod()
    {
        Method(new[] { new object() }); // Noncompliant - FP
    }
}

Following the S3878 suggestion to "remove the array creation and simply pass the elements" will result in a compiler error (type mismatch "cannot convert from object to object[]").

Expected behavior

No issue is raised.

Actual behavior

S3878 is raised.

Known workarounds

Move the array creation to a separate variable, then pass that variable as method parameter.

Related information

  • Visual Studio version: 17.6.1
  • MSBuild / dotnet version: .NET 7
  • SonarScanner for .NET version: Sonar Server Version 9.9.1 (build 69595) / SonarLint Version 7.3.0.77872
  • Operating System: Windows 10
@zsolt-kolbay-sonarsource zsolt-kolbay-sonarsource changed the title Fix S3878 FP: When params parameter is array of arrays Fix S3878 FP: Jagged arrays Oct 10, 2023
@zsolt-kolbay-sonarsource zsolt-kolbay-sonarsource added Type: False Positive Rule IS triggered when it shouldn't be. Area: VB.NET VB.NET rules related issues. Area: C# C# rules related issues. labels Oct 10, 2023
@zsolt-kolbay-sonarsource
Copy link
Contributor

Thank you for reporting this issue. Confirmed as False Positive.

@martin-strecker-sonarsource
Copy link
Contributor

Related #6894
Existing test case

MethodJuggedArray(new int[] { 1, 2 }); // Noncompliant, FP. Elements in args: [System.Object[]]

@Tim-Pohlmann Tim-Pohlmann added the Sprint: Hardening Fix FPs/FNs/improvements label Apr 9, 2024
@Tim-Pohlmann Tim-Pohlmann added this to the 9.24 milestone Apr 9, 2024
@Tim-Pohlmann Tim-Pohlmann added this to To do in Best Kanban Apr 9, 2024
@Tim-Pohlmann Tim-Pohlmann moved this from To do to In progress in Best Kanban Apr 10, 2024
@Tim-Pohlmann Tim-Pohlmann removed their assignment Apr 11, 2024
@Tim-Pohlmann Tim-Pohlmann moved this from In progress to To do in Best Kanban Apr 11, 2024
@CristianAmbrosini CristianAmbrosini moved this from To do to In progress in Best Kanban Apr 15, 2024
@CristianAmbrosini CristianAmbrosini self-assigned this Apr 15, 2024
@github-actions github-actions bot moved this from In progress to Review in progress in Best Kanban Apr 15, 2024
@github-actions github-actions bot moved this from Review in progress to Review approved in Best Kanban Apr 16, 2024
Best Kanban automation moved this from Review approved to Validate Peach Apr 17, 2024
@CristianAmbrosini CristianAmbrosini moved this from Validate Peach to Done in Best Kanban Apr 18, 2024
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. Area: VB.NET VB.NET rules related issues. Sprint: Hardening Fix FPs/FNs/improvements Type: False Positive Rule IS triggered when it shouldn't be.
Projects
Best Kanban
  
Done
Development

Successfully merging a pull request may close this issue.

5 participants