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
 
Tags
    Impact
      Clean code attribute
        1. Range methods should be used appropriately to avoid unexpected behavior

           Code Smell
        2. Property names should use camelCase

           Code Smell
        3. Simple "@Grab" annotations should use shorthand notation

           Code Smell
        4. GString expressions should not be used as map keys

           Bug
        5. Empty strings should not be used for type conversion

           Code Smell
        6. Static imports should appear before regular imports

           Code Smell
        7. Method names should not use reserved keywords

           Code Smell
        8. Do not use "sort(false)" to avoid confusion

           Code Smell
        9. Semicolons should be omitted in Groovy

           Code Smell
        10. Control structures should use braces

           Code Smell
        11. Duplicate import statements should be removed

           Code Smell
        12. Star imports should be replaced with explicit imports

           Code Smell
        13. AST transformation classes should be annotated with "@CompileStatic"

           Code Smell
        14. "@TimedInterrupt" should not be used on static methods

           Bug
        15. File operations should specify charset encoding

           Code Smell
        16. Test methods should contain assertions

           Code Smell
        17. Method names should follow camelCase naming conventions

           Code Smell
        18. Null checks should use correct logical operators

           Bug
        19. Classes with a "clone()" method should implement "Cloneable"

           Bug
        20. "wait()" calls should be inside "while" loops

           Bug
        21. Groovy parser failure

           Code Smell

        Null checks should use correct logical operators

        intentionality - logical
        reliability
        Bug

          This is an issue when logical operators are used incorrectly in null checks, potentially causing the code to access properties or methods on null objects.

          Why is this an issue?

          How can I fix it?

          More Info

          Faulty null checks can lead to NullPointerException at runtime, which crashes the application unexpectedly.

          The most common mistake is using the wrong logical operator when combining a null check with property or method access on the same variable:

          • Using OR (||) instead of AND (&&) when checking that an object is not null before accessing it
          • Using AND (&&) instead of OR (||) when checking that an object is null

          For example, if (name != null || name.length > 0) is problematic because:

          1. If name is not null, the first condition name != null is true
          2. Due to short-circuit evaluation, name.length > 0 won’t be evaluated, which might not be the intended behavior
          3. If name is null, the first condition is false, so the second condition name.length > 0 will be evaluated
          4. Accessing length on a null object throws a NullPointerException

          Similarly, if (record == null && record.id > 10) is wrong because if record is null, the first condition is true, but then record.id > 10 will still be evaluated, causing a NullPointerException.

          These logical errors are often typos or misunderstandings of how logical operators work with short-circuit evaluation.

          What is the potential impact?

          The application will crash with a NullPointerException when the faulty null check is executed and the object being checked is actually null. This can lead to:

          • Application downtime and poor user experience
          • Data loss if the exception occurs during critical operations
          • Security vulnerabilities if error handling is inadequate
          • Difficult debugging, especially in production environments where the exact conditions causing the null reference may be hard to reproduce
            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