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
Java

Java static code analysis

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

  • All rules 733
  • Vulnerability60
  • Bug175
  • Security Hotspot40
  • Code Smell458

  • Quick Fix 65
Filtered: 6 rules found
java14
    Impact
      Clean code attribute
        1. Comma-separated labels should be used in Switch with colon case

           Code Smell
        2. Switch arrow labels should not use redundant keywords

           Code Smell
        3. Escape sequences should not be used in text blocks

           Code Smell
        4. Whitespace for text block indent should be consistent

           Code Smell
        5. Simple string literal should be used for single line strings

           Code Smell
        6. Use Java 14 "switch" expression

           Code Smell

        Switch arrow labels should not use redundant keywords

        intentionality - clear
        maintainability
        Code Smell
        • java14

        Why is this an issue?

        More Info

        In Switch Expressions, an arrow label consisting of a block with a single yield can be simplified to directly return the value, resulting in cleaner code.

        Similarly, for Switch Statements and arrow labels, a break in a block is always redundant and should not be used. Furthermore, if the resulting block contains only one statement, the curly braces of that block can also be omitted.

        This rule reports an issue when a case of a Switch Expression contains a block with a single yield or when a Switch Statement contains a block with a break.

        Noncompliant code example

        int i = switch (mode) {
          case "a" -> {        // Noncompliant: Remove the redundant block and yield.
            yield 1;
          }
          default -> {         // Noncompliant: Remove the redundant block and yield.
            yield 2;
          }
        };
        
        switch (mode) {
          case "a" -> {        // Noncompliant: Remove the redundant block and break.
            result = 1;
            break;
          }
          default -> {         // Noncompliant: Remove the redundant break.
            doSomethingElse();
            result = 2;
            break;
          }
        }
        

        Compliant solution

        int i = switch (mode) {
          case "a" -> 1;
          default -> 2;
        };
        
        switch (mode) {
          case "a" -> result = 1;
          default -> {
           doSomethingElse();
           result = 2;
         }
        }
        
          Available In:
        • SonarQube IdeCatch issues on the fly,
          in your IDE
        • SonarQube CloudDetect issues in your GitHub, Azure DevOps Services, Bitbucket Cloud, GitLab repositories
        • SonarQube Community BuildAnalyze code in your
          on-premise CI
          Available Since
          9.1
        • SonarQube ServerAnalyze code in your
          on-premise CI
          Developer Edition
          Available Since
          9.1

        © 2008-2025 SonarSource SA. All rights reserved.

        Privacy Policy | Cookie Policy | Terms of Use