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.
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[]]

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
None yet
Development

Successfully merging a pull request may close this issue.

5 participants