All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.plugins.vbnet.S3453.html Maven / Gradle / Ivy

There is a newer version: 10.5.0.109200
Show newest version

Why is this an issue?

When a class has only a private constructor, it can’t be instantiated except within the class itself. Such classes can be considered dead code and should be fixed

Exceptions

  • Classes that access their private constructors (singletons or smart enums) are ignored.
  • Classes with only static members are also ignored because they are covered by Rule {rule:vbnet:S1118}.
  • Classes that derive from SafeHandle since they can be instantiate through P/Invoke.

How to fix it

Code examples

Noncompliant code example

Public Class [MyClass] ' Noncompliant: the class contains only private constructors
    Private Sub New()
        ' ...
    End Sub
End Class

Compliant solution

Public Class [MyClass] ' Compliant: the class contains at least one non-private constructor
    Public Sub New()
        ' ...
    End Sub
End Class

Resources

Documentation





© 2015 - 2025 Weber Informatics LLC | Privacy Policy