Uploaded image for project: 'Rules Repository'
  1. Rules Repository
  2. RSPEC-2974

Classes without "public" constructors should be "final"

    XMLWordPrintable

    Details

    • Type: Code Smell Detection
    • Status: Active
    • Resolution: Unresolved
    • Labels:
    • Message:
      Make this class "final" or add a public constructor.
    • Default Severity:
      Minor
    • Impact:
      Low
    • Likelihood:
      Low
    • Covered Languages:
      Java
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      5min
    • Analysis Scope:
      Main Sources
    • Checkstyle:
      FinalClass
    • PMD:
      ClassWithOnlyPrivateConstructorsShouldBeFinal

      Description

      Classes with only private constructors should be marked final to prevent any mistaken extension attempts.

      Noncompliant Code Example

      public class PrivateConstructorClass {  // Noncompliant
        private PrivateConstructorClass() {
          // ...
        }
      
        public static int magic(){
          return 42;
        }
      }
      

      Compliant Solution

      public final class PrivateConstructorClass {  // Compliant
        private PrivateConstructorClass() {
          // ...
        }
      
        public static int magic(){
          return 42;
        }
      }
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              ann.campbell.2 Ann Campbell
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated: