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: 30 rules found
regex
    Impact
      Clean code attribute
        1. Character classes in regular expressions should not contain only one character

           Code Smell
        2. Superfluous curly brace quantifiers should be avoided

           Code Smell
        3. Non-capturing groups without quantifier should not be used

           Code Smell
        4. Regular expression quantifiers and character classes should be used concisely

           Code Smell
        5. Regular expressions should not contain empty groups

           Code Smell
        6. Regular expressions should not contain multiple spaces

           Code Smell
        7. The regex escape sequence \cX should only be used with characters in the @-_ range

           Bug
        8. Single-character alternations in regular expressions should be replaced with character classes

           Code Smell
        9. Reluctant quantifiers in regular expressions should be followed by an expression that can't match the empty string

           Code Smell
        10. Regex lookahead assertions should not be contradictory

           Bug
        11. Back references in regular expressions should only refer to capturing groups that are matched before the reference

           Bug
        12. Regular expressions should not overflow the stack

           Bug
        13. Regex boundaries should not be used in a way that can never be matched

           Bug
        14. Regex patterns following a possessive quantifier should not always fail

           Bug
        15. Character classes in regular expressions should not contain the same character twice

           Code Smell
        16. Unicode Grapheme Clusters should be avoided inside regex character classes

           Bug
        17. Unicode-aware versions of character classes should be preferred

           Code Smell
        18. Case insensitive Unicode regular expressions should enable the "UNICODE_CASE" flag

           Bug
        19. Names of regular expressions named groups should be used

           Code Smell
        20. Character classes should be preferred over reluctant quantifiers in regular expressions

           Code Smell
        21. Regular expressions should be syntactically valid

           Bug
        22. Regex alternatives should not be redundant

           Bug
        23. Regexes containing characters subject to normalization should use the CANON_EQ flag

           Code Smell
        24. Using slow regular expressions is security-sensitive

           Security Hotspot
        25. Alternatives in regular expressions should be grouped when used with anchors

           Bug
        26. Empty lines should not be tested with regex MULTILINE flag

           Code Smell
        27. Regular expressions should not be too complicated

           Code Smell
        28. Repeated patterns in regular expressions should not match the empty string

           Bug
        29. "String#replace" should be preferred to "String#replaceAll"

           Code Smell
        30. Regex patterns should not be created needlessly

           Code Smell

        Regex alternatives should not be redundant

        intentionality - clear
        reliability
        Bug
        • regex

        This rule raises an issue when multiple branches of a regex alternative match the same input.

        Why is this an issue?

        If an alternative in a regular expression only matches things that are already matched by another alternative, that alternative is redundant and serves no purpose.

        In the best case this means that the offending subpattern is merely redundant and should be removed. In the worst case it’s a sign that this regex does not match what it was intended to match and should be reworked.

        Code examples

        Noncompliant code example

        "[ab]|a"   // Noncompliant: the "|a" is redundant because "[ab]" already matches "a"
        ".*|a"     // Noncompliant: .* matches everything, so any other alternative is redundant
        

        Compliant solution

        "[ab]"
        ".*"
        
          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