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: 37 rules found
suspicious
    Impact
      Clean code attribute
        1. Equality operators should not be used in "for" loop termination conditions

           Code Smell
        2. Methods should not have identical implementations

           Code Smell
        3. Map values should not be replaced unconditionally

           Bug
        4. Collection contents should be used

           Code Smell
        5. Week Year ("YYYY") should not be used for date formatting

           Bug
        6. A conditionally executed single line should be denoted by indentation

           Code Smell
        7. Conditionals should start on new lines

           Code Smell
        8. Number patterns should be regular

           Code Smell
        9. Assertion arguments should be passed in the correct order

           Code Smell
        10. Tests should be kept in a dedicated source directory

           Code Smell
        11. "this" should not be exposed from constructors

           Code Smell
        12. "ThreadGroup" should not be used

           Code Smell
        13. "clone" should not be overridden

           Code Smell
        14. "indexOf" checks should not be for positive numbers

           Code Smell
        15. "Math.abs" and negation should not be used on numbers that could be "MIN_VALUE"

           Bug
        16. Method overrides should not change contracts

           Code Smell
        17. Boolean expressions should not be gratuitous

           Code Smell
        18. Conditionally executed code should be reachable

           Bug
        19. Unnecessary bit operations should not be performed

           Code Smell
        20. Java parser failure

           Code Smell
        21. Modulus results should not be checked for direct equality

           Code Smell
        22. Recursion should not be infinite

           Bug
        23. Subclasses that add fields to classes that override "equals" should also override "equals"

           Code Smell
        24. Two branches in a conditional structure should not have exactly the same implementation

           Code Smell
        25. "Object.wait" should not be called on objects that implement "java.util.concurrent.locks.Condition"

           Code Smell
        26. "==" and "!=" should not be used when "equals" is overridden

           Code Smell
        27. JUnit4 @Ignored and JUnit5 @Disabled annotations should be used to disable tests and should provide a rationale

           Code Smell
        28. Switch cases should end with an unconditional "break" statement

           Code Smell
        29. "switch" statements should not contain non-case labels

           Code Smell
        30. "equals" method overrides should accept "Object" parameters

           Bug
        31. Methods should not be empty

           Code Smell
        32. Exception handlers should preserve the original exceptions

           Code Smell
        33. Exceptions should not be thrown in finally blocks

           Code Smell
        34. Exit methods should not be called

           Code Smell
        35. Assignments should not be made from within sub-expressions

           Code Smell
        36. Local variables should not shadow class fields

           Code Smell
        37. Nested blocks of code should not be left empty

           Code Smell

        "Object.wait" should not be called on objects that implement "java.util.concurrent.locks.Condition"

        intentionality - clear
        maintainability
        Code Smell
        • suspicious

        Why is this an issue?

        More Info

        The java.util.concurrent.locks.Condition interface provides an alternative to the Object monitor methods (wait, notify and notifyAll). Hence, the purpose of implementing said interface is to gain access to its more nuanced await methods.

        Consequently, calling the method Object.wait on a class implementing the Condition interface is contradictory and should be avoided. Use Condition.await instead.

        Code examples

        Noncompliant code example

        void doSomething(Condition condition) {
            condition.wait(); // Noncompliant, Object.wait is called
        
                ...
        }
        

        Compliant solution

        void doSomething(Condition condition) {
            condition.await(); // Compliant, Condition.await is called
        
                ...
        }
        
          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