C# Use of private constructor not detected when using new keyword

Then tell us:

  • What language is this for?
    C#

  • Which rule?
    csharpsquid:S3453 and csharpsquid:S1144

  • Why do you believe it’s a false-positive/false-negative?
    I do indeed use this private constructor in a static list just with the new keyword instead of the full qualified class name.

  • Are you using

    • SonarQube Cloud?
      Yes sonarcloud team services
    • SonarQube for IDE - which IDE/version?
      10.22.0.81244 in connected mode with our sonarcloud
  • How can we reproduce the problem? Give us a self-contained snippet of code (formatted text, no screenshots)’

The file creating the issue is in the following github gist. I anonymized the file but the issue remains the same.

Hello @lars-at-joz thanks for the report!

Unfortunately I cannot reproduce the issue. Can you confirm that I got everything correct?

  1. I had to simplify the code snippet a bit, but that shouldn’t change much. Does this snippet raise S1144 for you?
    internal class LogConverter
    {
        private LogConverter(string regex, string alertType)
        {
            AlertType = alertType;
        }

        public string AlertType { get; }

        public static readonly LogConverter[] Converters =
        [
            new("^AGV route completed", "0xAAFF0001"),
            new("^AGV route failed during execution", "0xAAFF0002"),
        ];
    }
  1. You are using SonarQube for IDE in IntelliJ’s Rider (I inferred that from the version you mentioned).

We did not touch S1144 in a while and the version you are using is recent. So it’s not quite obvious what could be different. Please double check that my reproduction attempt does in fact raise the issue for you and then I’ll try to investigate deeper.