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
  • GroovyGroovy
  • 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
Groovy

Groovy static code analysis

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

  • All rules 21
  • Bug5
  • Code Smell16
Filtered: 1 rule found
formatting
    Impact
      Clean code attribute
        1. Control structures should use braces

           Code Smell

        Control structures should use braces

        consistency - conventional
        maintainability
        Code Smell
        • convention
        • formatting

        This rule raises an issue when control structures like if, else, while, or for statements have a body without braces, even for single statements.

        Why is this an issue?

        How can I fix it?

        More Info

        Control structures without braces can lead to maintenance problems and bugs. When a developer later adds a second statement to what appears to be a block, they might forget to add braces, causing the second statement to execute outside the intended control flow.

        Consider this example:

        if (condition)
            doSomething()
            doSomethingElse()  // This always executes!
        

        The second statement doSomethingElse() will always execute, regardless of the condition, because it’s not part of the if statement. This is a common source of bugs that can be difficult to spot during code review.

        Using braces makes the code structure explicit and prevents these types of errors. It also improves readability by clearly showing where each control block begins and ends, especially in nested structures.

        What is the potential impact?

        Without braces, code modifications can introduce logic errors where statements execute outside their intended control flow. This can lead to incorrect program behavior, security vulnerabilities, or data corruption. The impact is particularly severe when the unintended execution involves security checks, resource management, or critical business logic.

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

        © 2026 SonarSource Sàrl. All rights reserved.

        Privacy Policy | Cookie Policy | Terms of Use