SonarSource Rules
  • Products

    In-IDE

    Code Quality and Security in your IDE with SonarQube Ide

    IDE extension that lets you fix coding issues before they exist!

    Discover SonarQube for IDE

    SaaS

    Code Quality and Security in the cloud with SonarQube Cloud

    Setup is effortless and analysis is automatic for most languages

    Discover SonarQube Cloud

    Self-Hosted

    Code Quality and Security Self-Hosted with SonarQube Server

    Fast, accurate analysis; enterprise scalability

    Discover SonarQube Server
  • SecretsSecrets
  • ABAPABAP
  • AnsibleAnsible
  • ApexApex
  • AzureResourceManagerAzureResourceManager
  • CC
  • C#C#
  • C++C++
  • CloudFormationCloudFormation
  • COBOLCOBOL
  • CSSCSS
  • DartDart
  • DockerDocker
  • FlexFlex
  • GitHub ActionsGitHub Actions
  • GoGo
  • HTMLHTML
  • JavaJava
  • JavaScriptJavaScript
  • JSONJSON
  • JCLJCL
  • KotlinKotlin
  • KubernetesKubernetes
  • Objective CObjective C
  • PHPPHP
  • PL/IPL/I
  • PL/SQLPL/SQL
  • PythonPython
  • RPGRPG
  • RubyRuby
  • RustRust
  • ScalaScala
  • ShellShell
  • SwiftSwift
  • TerraformTerraform
  • TextText
  • TypeScriptTypeScript
  • T-SQLT-SQL
  • VB.NETVB.NET
  • VB6VB6
  • XMLXML
  • YAMLYAML
Apex

Apex static code analysis

Unique rules to find Bugs, Vulnerabilities, Security Hotspots, and Code Smells in your APEX code

  • All rules 97
  • Vulnerability2
  • Bug26
  • Security Hotspot3
  • Code Smell66
Filtered: 1 rule found
design-patterns
    Impact
      Clean code attribute
        1. Builder pattern methods should return the builder instance to enable method chaining

           Code Smell

        Builder pattern methods should return the builder instance to enable method chaining

        consistency - conventional
        maintainability
        Code Smell
        • design-patterns

        This rule raises an issue when a builder class method that sets a property returns void instead of returning the builder instance.

        Why is this an issue?

        How can I fix it?

        More Info

        The Builder design pattern is used to construct complex objects step by step through a fluent interface. One of the key benefits of this pattern is method chaining, which allows developers to write readable, expressive code like builder.setName("John").setAge(25).build().

        When builder methods return void instead of the builder instance, method chaining becomes impossible. This forces developers to write verbose code with multiple separate statements, reducing the readability and fluency that makes the Builder pattern attractive.

        Method chaining in builders creates a more natural, English-like syntax that clearly expresses the intent of constructing an object with specific properties. Without it, the builder loses much of its ergonomic advantage over traditional constructors or setter methods.

        What is the potential impact?

        The code becomes more verbose and less readable. Developers lose the fluent interface benefits that make the Builder pattern attractive, potentially leading to inconsistent usage patterns and reduced code maintainability.

          Available In:
        • SonarQube CloudDetect issues in your GitHub, Azure DevOps Services, Bitbucket Cloud, GitLab repositories

        © 2008-2025 SonarSource SA. All rights reserved.

        Privacy Policy | Cookie Policy | Terms of Use