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: 452 rules found
Tags
    maintainability
      Clean code attribute
        1. Functions should not be defined with a variable number of arguments

           Code Smell
        2. Equality operators should not be used in "for" loop termination conditions

           Code Smell
        3. Increment (++) and decrement (--) operators should not be used in a method call or mixed with other operators in an expression

           Code Smell
        4. Limited dependence should be placed on operator precedence

           Code Smell
        5. Literal suffixes should be upper case

           Code Smell
        6. When a defaultFinisher is passed to a Gatherer factory, use the overload that does not take a finisher

           Code Smell
        7. Don't provide an initializer for a stateless stream gatherer

           Code Smell
        8. Gatherer.ofSequential() should be used to build sequential gathers

           Code Smell
        9. "ClassBuilder.withMethodBody" should be preferred to "ClassBuilder.withMethod"

           Code Smell
        10. "transformClass" method should be used instead of "build" when transforming a class

           Code Smell
        11. Class name should be omitted when unchanged by class transform

           Code Smell
        12. Comments should start with the appropriate number of slashes

           Code Smell
        13. Types of unused record components should be removed from pattern matching

           Code Smell
        14. Markdown, HTML and Javadoc tags should be consistent

           Code Smell
        15. Unused exception parameter should use the unnamed variable pattern

           Code Smell
        16. Unnamed variable declarations should use the "var" identifier

           Code Smell
        17. Methods annotated with "@BeforeTransaction" or "@AfterTransaction" must respect the contract

           Code Smell
        18. Methods returning "Page" or "Slice" must take "Pageable" as an input parameter

           Code Smell
        19. "@Scheduled" annotation should only be applied to no-arg methods

           Bug
        20. "@Cache*" annotations should only be applied on concrete classes

           Code Smell
        21. Injecting data into static fields is not supported by Spring

           Code Smell
        22. "String.isEmpty()" should be used to test for emptiness

           Code Smell
        23. Circular dependencies between classes across packages should be resolved

           Code Smell
        24. Circular dependencies between classes in the same package should be resolved

           Code Smell
        25. Bluetooth should be configured to use low power

           Code Smell
        26. Motion Sensor should not use gyroscope

           Code Smell
        27. Use when instead of a single if inside a pattern match body

           Code Smell
        28. Use Fused Location to optimize battery power

           Code Smell
        29. Use batch Processing in JDBC

           Code Smell
        30. Constant parameters in a "PreparedStatement" should not be set more than once

           Code Smell
        31. SQL queries should retrieve only necessary fields

           Code Smell
        32. Avoid using "FetchType.EAGER"

           Code Smell
        33. High frame rates should not be used

           Code Smell
        34. Exact alarms should not be abused

           Code Smell
        35. Proper Sensor Resource Management

           Code Smell
        36. Use built-in "Math.clamp" methods

           Code Smell
        37. Use switch instead of if-else chain to compare a variable against multiple cases

           Code Smell
        38. Use record pattern instead of explicit field access

           Code Smell
        39. Reverse view should be used instead of reverse copy in read-only cases

           Code Smell
        40. Reverse iteration should utilize reversed view

           Code Smell
        41. Superfluous "@ResponseBody" annotations should be removed

           Code Smell
        42. "@Controller" should be replaced with "@RestController"

           Code Smell
        43. "@Qualifier" should not be used on "@Bean" methods

           Bug
        44. Bean names should adhere to the naming conventions

           Code Smell
        45. "@Autowired" should be used when multiple constructors are provided

           Code Smell
        46. "@Autowired" should only be used on a single constructor

           Bug
        47. Field dependency injection should be avoided

           Code Smell
        48. Methods with Spring proxy should not be called via "this"

           Code Smell
        49. Model attributes should follow the Java identifier naming convention

           Bug
        50. "@Value" annotation should inject property or SpEL expression

           Code Smell
        51. The Singleton design pattern should be used with care

           Code Smell
        52. Methods should not perform too many tasks (aka Brain method)

           Code Smell
        53. Classes should not depend on an excessive number of classes (aka Monster Class)

           Code Smell
        54. Hash-based collections with known capacity should be initialized with the proper related static method.

           Code Smell
        55. Types used as keys in Maps should implement Comparable

           Code Smell
        56. Character classes in regular expressions should not contain only one character

           Code Smell
        57. Superfluous curly brace quantifiers should be avoided

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

           Code Smell
        59. Deprecated annotations should include explanations

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

           Code Smell
        61. Regular expressions should not contain empty groups

           Code Smell
        62. Regular expressions should not contain multiple spaces

           Code Smell
        63. AWS region should not be set with a hardcoded String

           Code Smell
        64. Lambdas should not invoke other lambdas synchronously

           Code Smell
        65. Consumer Builders should be used

           Code Smell
        66. Reusable resources should be initialized at construction time of Lambda functions

           Code Smell
        67. Credentials Provider should be set explicitly when creating a new "AwsClient"

           Code Smell
        68. Region should be set explicitly when creating a new "AwsClient"

           Code Smell
        69. 'serialVersionUID' field should not be set to '0L' in records

           Code Smell
        70. Permitted types of a sealed class should be omitted if they are declared in the same file

           Code Smell
        71. Restricted Identifiers should not be used as Identifiers

           Code Smell
        72. Local-Variable Type Inference should be used

           Code Smell
        73. Custom getter method should not be used to override record's getter behavior

           Code Smell
        74. Comma-separated labels should be used in Switch with colon case

           Code Smell
        75. Redundant constructors/methods should be avoided in records

           Code Smell
        76. Records should be used instead of ordinary classes when representing immutable data structure

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

           Code Smell
        78. "Stream.toList()" method should be used instead of "collectors" when unmodifiable list needed

           Code Smell
        79. Text blocks should not be used in complex expressions

           Code Smell
        80. Operator "instanceof" should be used instead of "A.class.isInstance()"

           Code Smell
        81. Pattern Matching for "instanceof" operator should be used instead of simple "instanceof" + cast

           Code Smell
        82. String multiline concatenation should be replaced with Text Blocks

           Code Smell
        83. Call to Mockito method "verify", "when" or "given" should be simplified

           Code Smell
        84. Single-character alternations in regular expressions should be replaced with character classes

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

           Code Smell
        86. Constructors of an "abstract" class should not be declared "public"

           Code Smell
        87. Tests should use fixed data instead of randomized data

           Code Smell
        88. Similar tests should be grouped in a single Parameterized test

           Code Smell
        89. Tests should be stable

           Code Smell
        90. Spring's ModelAndViewAssert assertions should be used instead of other assertions

           Code Smell
        91. Mocking all non-private methods of a class should be avoided

           Code Smell
        92. Test methods should not contain too many assertions

           Code Smell
        93. AssertJ "assertThatThrownBy" should not be used alone

           Code Smell
        94. Character classes in regular expressions should not contain the same character twice

           Code Smell
        95. Unicode-aware versions of character classes should be preferred

           Code Smell
        96. Names of regular expressions named groups should be used

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

           Code Smell
        98. Regexes containing characters subject to normalization should use the CANON_EQ flag

           Code Smell
        99. Consecutive AssertJ "assertThat" statements should be chained

           Code Smell
        100. Empty lines should not be tested with regex MULTILINE flag

           Code Smell
        101. Regular expressions should not be too complicated

           Code Smell
        102. Chained AssertJ assertions should be simplified to the corresponding dedicated assertion

           Code Smell
        103. Methods setUp() and tearDown() should be correctly annotated starting with JUnit4

           Code Smell
        104. Class members annotated with "@VisibleForTesting" should not be accessed from production code

           Code Smell
        105. Migrate your tests from JUnit4 to the new JUnit5 annotations

           Code Smell
        106. JUnit5 test classes and methods should have default package visibility

           Code Smell
        107. JUnit assertTrue/assertFalse should be simplified to the corresponding dedicated assertion

           Code Smell
        108. Only one method invocation is expected when testing runtime exceptions

           Code Smell
        109. Exception testing via JUnit @Test annotation should be avoided

           Code Smell
        110. Exception testing via JUnit ExpectedException rule should not be mixed with other assertions

           Code Smell
        111. "@Deprecated" code marked for removal should never be used

           Code Smell
        112. Vararg method arguments should not be confusing

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

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

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

           Code Smell
        116. Lambdas should not have too many lines

           Code Smell
        117. 'List.remove()' should not be used in ascending 'for' loops

           Code Smell
        118. Avoid using boxed "Boolean" types directly in boolean expressions

           Code Smell
        119. "String#replace" should be preferred to "String#replaceAll"

           Code Smell
        120. Collection constructors should not be used as java.util.function.Function

           Code Smell
        121. "else" statements should be clearly matched with an "if"

           Code Smell
        122. Use Java 14 "switch" expression

           Code Smell
        123. "Bean Validation" (JSR 380) should be properly configured

           Code Smell
        124. Type parameters should not shadow other type parameters

           Code Smell
        125. Derived exceptions should not hide their parents' catch blocks

           Code Smell
        126. The upper bound of type variables and wildcards should not be "final"

           Code Smell
        127. "read(byte[],int,int)" should be overridden

           Code Smell
        128. "serialVersionUID" should not be declared blindly

           Code Smell
        129. "Class.forName()" should not load JDBC 4.0+ drivers

           Code Smell
        130. An iteration on a Collection should be performed on the type handled by the Collection

           Code Smell
        131. Java features should be preferred to Guava

           Code Smell
        132. "StandardCharsets" constants should be preferred

           Code Smell
        133. "@CheckForNull" or "@Nullable" should not be used on primitive types

           Code Smell
        134. String offset-based methods should be preferred for finding substrings from offsets

           Code Smell
        135. Spring beans should be considered by "@ComponentScan"

           Code Smell
        136. Enum values should be compared with "=="

           Code Smell
        137. "default" clauses should be last

           Code Smell
        138. Composed "@RequestMapping" variants should be preferred

           Code Smell
        139. "equals" method parameters should not be marked "@Nonnull"

           Code Smell
        140. Nullness of parameters should be guaranteed

           Code Smell
        141. "Integer.toHexString" should not be used to build hexadecimal strings

           Code Smell
        142. "write(byte[],int,int)" should be overridden

           Code Smell
        143. Spring components should use constructor injection

           Code Smell
        144. Functional Interfaces should be as specialised as possible

           Code Smell
        145. Asserts should not be used to check the parameters of a public method

           Code Smell
        146. "Stream.collect()" calls should not be redundant

           Code Smell
        147. Regex patterns should not be created needlessly

           Code Smell
        148. Null checks should not be used with "instanceof"

           Code Smell
        149. Local constants should follow naming conventions for constants

           Code Smell
        150. Assignments should not be redundant

           Code Smell
        151. Methods should not have identical implementations

           Code Smell
        152. "close()" calls should not be redundant

           Code Smell
        153. "ThreadLocal.withInitial" should be preferred

           Code Smell
        154. "java.nio.Files#delete" should be preferred

           Code Smell
        155. "Stream" call chains should be simplified when possible

           Code Smell
        156. Packages containing only "package-info.java" should be removed

           Code Smell
        157. Collection contents should be used

           Code Smell
        158. Track uses of disallowed constructors

           Code Smell
        159. Unused "private" classes should be removed

           Code Smell
        160. A conditionally executed single line should be denoted by indentation

           Code Smell
        161. Conditionals should start on new lines

           Code Smell
        162. Number patterns should be regular

           Code Smell
        163. Arrays should not be created for varargs parameters

           Code Smell
        164. "Stream.peek" should be used with caution

           Code Smell
        165. "Map.get" and value test should be replaced with single method call

           Code Smell
        166. Cognitive Complexity of methods should not be too high

           Code Smell
        167. "@RequestMapping" methods should not be "private"

           Code Smell
        168. Members of Spring components should be injected

           Code Smell
        169. Raw types should not be used

           Code Smell
        170. Java 8's "Files.exists" should not be used

           Code Smell
        171. Track uses of disallowed classes

           Code Smell
        172. Unit tests should throw exceptions

           Code Smell
        173. "Arrays.stream" should be used for primitive arrays

           Code Smell
        174. Jump statements should not be redundant

           Code Smell
        175. Test methods should comply with a naming convention

           Code Smell
        176. Test classes should comply with a naming convention

           Code Smell
        177. "Optional" should not be used for parameters

           Code Smell
        178. Methods returns should not be invariant

           Code Smell
        179. Format strings should be used correctly

           Code Smell
        180. Value-based objects should not be serialized

           Code Smell
        181. Loggers should be named for their enclosing classes

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

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

           Code Smell
        184. Methods should not return constants

           Code Smell
        185. "private" methods called only by inner classes should be moved to those classes

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

           Code Smell
        187. Ternary operators should not be nested

           Code Smell
        188. Factory method injection should be used in "@Configuration" classes

           Code Smell
        189. Default annotation parameter values should not be passed as arguments

           Code Smell
        190. "static" base class members should not be accessed via derived types

           Code Smell
        191. Method parameters should be declared with base types

           Code Smell
        192. "enum" fields should not be publicly mutable

           Code Smell
        193. "StringBuilder" data should be used

           Code Smell
        194. Fields should not be initialized to default values

           Code Smell
        195. Multiple loops over the same set should be combined

           Code Smell
        196. "writeObject" should not be the only "synchronized" code in a class

           Code Smell
        197. Abstract methods should not be redundant

           Code Smell
        198. ".isEmpty" should be used to test for the emptiness of StringBuffers/Builders

           Code Smell
        199. Classes should not have too many "static" imports

           Code Smell
        200. Arguments to "append" should not be concatenated

           Code Smell
        201. "ThreadGroup" should not be used

           Code Smell
        202. Arrays and lists should not be copied using loops

           Code Smell
        203. Reflection should not be used to increase accessibility of classes, methods, or fields

           Code Smell
        204. Static fields should not be updated in constructors

           Code Smell
        205. Static non-final field names should comply with a naming convention

           Code Smell
        206. "clone" should not be overridden

           Code Smell
        207. Classes without "public" constructors should be "final"

           Code Smell
        208. Escaped Unicode characters should not be used

           Code Smell
        209. Inner classes should not have too many lines of code

           Code Smell
        210. Assertions should be complete

           Code Smell
        211. Unnecessary semicolons should be omitted

           Code Smell
        212. "Thread.sleep" should not be used in tests

           Code Smell
        213. JUnit rules should be used

           Code Smell
        214. "entrySet()" should be iterated when both the key and value are needed

           Code Smell
        215. Nested "enum"s should not be declared static

           Code Smell
        216. "catch" clauses should do more than rethrow

           Code Smell
        217. "DateUtils.truncate" from Apache Commons Lang library should not be used

           Code Smell
        218. Literal boolean values and nulls should not be used in assertions

           Code Smell
        219. Tests should include assertions

           Code Smell
        220. Test assertions should include messages

           Code Smell
        221. Instance methods should not write to "static" fields

           Code Smell
        222. Inner classes which do not reference their owning classes should be "static"

           Code Smell
        223. Threads should not be started in constructors

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

           Code Smell
        225. Multiline blocks should be enclosed in curly braces

           Code Smell
        226. "readObject" should not be "synchronized"

           Code Smell
        227. Method overrides should not change contracts

           Code Smell
        228. "Preconditions" and logging arguments should not require evaluation

           Code Smell
        229. Boolean expressions should not be gratuitous

           Code Smell
        230. Whitespace and control characters in literals should be explicit

           Code Smell
        231. "null" should not be returned from a "Boolean" method

           Code Smell
        232. Lazy initialization of "static" fields should be "synchronized"

           Code Smell
        233. Synchronizing on a "Lock" object should be avoided

           Code Smell
        234. Classes with only "static" methods should not be instantiated

           Code Smell
        235. "Thread" should not be used where a "Runnable" argument is expected

           Code Smell
        236. Unnecessary bit operations should not be performed

           Code Smell
        237. Inner class calls to super class methods should be unambiguous

           Code Smell
        238. Child class fields should not shadow parent class fields

           Code Smell
        239. Mutable fields should not be "public static"

           Code Smell
        240. Private mutable members should not be stored or returned directly

           Code Smell
        241. Redundant modifiers should not be used

           Code Smell
        242. Unused type parameters should be removed

           Code Smell
        243. "private" and "final" methods that don't access instance data should be "static"

           Code Smell
        244. Files should not be empty

           Code Smell
        245. "deleteOnExit" should not be used

           Code Smell
        246. Public methods should not contain selector arguments

           Code Smell
        247. The diamond operator ("<>") should be used

           Code Smell
        248. "Object.wait(...)" and "Condition.await(...)" should be called inside a "while" loop

           Code Smell
        249. Track uses of disallowed methods

           Code Smell
        250. Collection methods with O(n) performance should be used carefully

           Code Smell
        251. "IllegalMonitorStateException" should not be caught

           Code Smell
        252. Parameters should be passed in the correct order

           Code Smell
        253. "ResultSet.isLast()" should not be used

           Code Smell
        254. "Exception" should not be caught when not required by called methods

           Code Smell
        255. Types should be used in lambdas

           Code Smell
        256. "static" members should be accessed statically

           Code Smell
        257. Wildcard imports should not be used

           Code Smell
        258. "collect" should be used with "Streams" instead of "list::add"

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

           Code Smell
        260. Switches should be used for sequences of simple "String" tests

           Code Smell
        261. JUnit test cases should call super methods

           Code Smell
        262. TestCases should contain tests

           Code Smell
        263. JUnit assertions should not be used in "run" methods

           Code Smell
        264. Do not perform unnecessary mathematical operations

           Code Smell
        265. Short-circuit logic should be used in boolean contexts

           Code Smell
        266. Class names should not shadow interfaces or superclasses

           Code Smell
        267. Classes named like "Exception" should extend "Exception" or a subclass

           Code Smell
        268. Subclasses that add fields to classes that override "equals" should also override "equals"

           Code Smell
        269. "Cloneables" should implement "clone"

           Code Smell
        270. "final" classes should not have "protected" members

           Code Smell
        271. Underscores should be used to make large numbers readable

           Code Smell
        272. Catches should be combined

           Code Smell
        273. "java.time" classes should be used for dates and times

           Code Smell
        274. Methods of "Random" that return floating point values should not be used in random integer generation

           Code Smell
        275. Exceptions should be either logged or rethrown but not both

           Code Smell
        276. Objects should not be created only to invoke "getClass"

           Code Smell
        277. Parsing should be used to convert "Strings" to primitives

           Code Smell
        278. Constructors should not be used to instantiate "String", "BigInteger", "BigDecimal" and primitive-wrapper classes

           Code Smell
        279. "URL.hashCode" and "URL.equals" should be avoided

           Code Smell
        280. "main" should not "throw" anything

           Code Smell
        281. Classes should not be empty

           Code Smell
        282. Try-with-resources should be used

           Code Smell
        283. Formatting SQL queries is security-sensitive

           Security Hotspot
        284. Fields in non-serializable classes should not be "transient"

           Code Smell
        285. Comparators should be "Serializable"

           Code Smell
        286. "readResolve" methods should be inheritable

           Code Smell
        287. "Serializable" inner classes of "Serializable" classes should be static

           Code Smell
        288. "Serializable" classes should have a "serialVersionUID"

           Code Smell
        289. The names of methods with boolean return values should start with "is" or "has"

           Code Smell
        290. Member variable visibility should be specified

           Code Smell
        291. Files should contain only one top-level class or interface each

           Code Smell
        292. "for" loop increment clauses should modify the loops' counters

           Code Smell
        293. Fields in a "Serializable" class should either be transient or serializable

           Code Smell
        294. Classes and methods that rely on the default system encoding should not be used

           Code Smell
        295. Simple class names should be used

           Code Smell
        296. Variables should not be declared before they are relevant

           Code Smell
        297. Boolean checks should not be inverted

           Code Smell
        298. Extensions and implementations should not be redundant

           Code Smell
        299. Redundant casts should not be used

           Code Smell
        300. "@Deprecated" code should not be used

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

           Code Smell
        302. "toString()" should never be called on a String object

           Code Smell
        303. Unused assignments should be removed

           Code Smell
        304. Methods and field names should not be the same or differ only by capitalization

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

           Code Smell
        306. "switch" statements and expressions should not be nested

           Code Smell
        307. Classes should not have too many fields

           Code Smell
        308. The ternary operator should not be used

           Code Smell
        309. Standard functional interfaces should not be redefined

           Code Smell
        310. Annotation repetitions should not be wrapped

           Code Smell
        311. A field should not duplicate the name of its containing class

           Code Smell
        312. Constructors should only call non-overridable methods

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

           Code Smell
        314. "NullPointerException" should not be caught

           Code Smell
        315. "NullPointerException" should not be explicitly thrown

           Code Smell
        316. An abstract class should have both abstract and concrete methods

           Code Smell
        317. Multiple variables should not be declared on the same line

           Code Smell
        318. Strings should not be concatenated using '+' in a loop

           Code Smell
        319. Sets with elements that are enum values should be replaced with EnumSet

           Code Smell
        320. Maps with keys that are enum values should use the EnumMap implementation

           Code Smell
        321. Lambdas should be replaced with method references

           Code Smell
        322. Parentheses should be removed from a single lambda parameter when its type is inferred

           Code Smell
        323. Abstract classes without fields should be converted to interfaces

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

           Code Smell
        325. Anonymous inner classes containing only one method should become lambdas

           Code Smell
        326. Lambdas containing only one statement should not nest this statement in a block

           Code Smell
        327. Package declaration should match source file directory

           Code Smell
        328. "Collections.EMPTY_LIST", "EMPTY_MAP", and "EMPTY_SET" should not be used

           Code Smell
        329. Methods should not be too complex

           Code Smell
        330. Local variables should not be declared and then immediately returned or thrown

           Code Smell
        331. Unused local variables should be removed

           Code Smell
        332. "switch" statements should not have too many "case" clauses

           Code Smell
        333. Generic wildcard types should not be used in return types

           Code Smell
        334. Track lack of copyright and license headers

           Code Smell
        335. Private fields only used as local variables in methods should become local variables

           Code Smell
        336. String operations should not rely on the default system locale

           Code Smell
        337. Classes should not have too many methods

           Code Smell
        338. "public static" fields should be constant

           Code Smell
        339. Comments should not be located at the end of lines of code

           Code Smell
        340. Methods should not have too many lines

           Code Smell
        341. Loops should not contain more than a single "break" or "continue" statement

           Code Smell
        342. Control flow statements "if", "for", "while", "switch" and "try" should not be nested too deeply

           Code Smell
        343. Declarations should use Java collection interfaces such as "List" rather than specific implementation classes such as "LinkedList"

           Code Smell
        344. Track uses of "CHECKSTYLE:OFF" suppression comments

           Code Smell
        345. Octal values should not be used

           Code Smell
        346. Loggers should be "private static final" and should share a naming convention

           Code Smell
        347. Track uses of "NOPMD" suppression comments

           Code Smell
        348. "switch" statements should have "default" clauses

           Code Smell
        349. Track uses of "@SuppressWarnings" annotations

           Code Smell
        350. "switch" statements should have at least 3 "case" clauses

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

           Code Smell
        352. "for" loop stop conditions should be invariant

           Code Smell
        353. A "while" loop should be used instead of a "for" loop

           Code Smell
        354. "if ... else if" constructs should end with "else" clauses

           Code Smell
        355. Classes and enums with private members should have a constructor

           Code Smell
        356. Sections of code should not be commented out

           Code Smell
        357. Track comments matching a regular expression

           Code Smell
        358. Packages should have a javadoc file 'package-info.java'

           Code Smell
        359. Non-constructor methods should not have the same name as the enclosing class

           Code Smell
        360. The default unnamed package should not be used

           Code Smell
        361. Statements should be on separate lines

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

           Code Smell
        363. Execution of the Garbage Collector should be triggered only by the JVM

           Code Smell
        364. Interfaces should not solely consist of constants

           Code Smell
        365. The members of an interface or class declaration should appear in a pre-defined order

           Code Smell
        366. "equals(Object obj)" should be overridden along with the "compareTo(T obj)" method

           Code Smell
        367. Control structures should use curly braces

           Code Smell
        368. Classes should not be coupled to too many other classes

           Code Smell
        369. Package names should comply with a naming convention

           Code Smell
        370. Nested code blocks should not be used

           Code Smell
        371. Array designators "[]" should be on the type, not the variable

           Code Smell
        372. Array designators "[]" should be located after the type in method signatures

           Code Smell
        373. "java.lang.Error" should not be extended

           Code Smell
        374. Exception types should not be tested using "instanceof" in catch blocks

           Code Smell
        375. String literals should not be duplicated

           Code Smell
        376. Classes from "sun.*" packages should not be used

           Code Smell
        377. Future keywords should not be used as names

           Code Smell
        378. Type parameter names should comply with a naming convention

           Code Smell
        379. Anonymous classes should not have too many lines

           Code Smell
        380. Methods should not be empty

           Code Smell
        381. Overriding methods should do more than simply call the same method in the super class

           Code Smell
        382. Classes that override "clone" should be "Cloneable" and call "super.clone()"

           Code Smell
        383. Throwable and Error should not be caught

           Code Smell
        384. Abstract class names should comply with a naming convention

           Code Smell
        385. Public types, methods and fields (API) should be documented with Javadoc

           Code Smell
        386. "Object.finalize()" should remain protected (versus public) when overriding

           Code Smell
        387. Unused method parameters should be removed

           Code Smell
        388. Only static class initializers should be used

           Code Smell
        389. Public constants and fields initialized at declaration should be "static final" rather than merely "final"

           Code Smell
        390. Local variable and method parameter names should comply with a naming convention

           Code Smell
        391. Empty arrays and collections should be returned instead of null

           Code Smell
        392. Exception handlers should preserve the original exceptions

           Code Smell
        393. Exception classes should have final fields

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

           Code Smell
        395. Checked exceptions should not be thrown

           Code Smell
        396. "@Override" should be used on overriding and implementing methods

           Code Smell
        397. Public methods should throw at most one checked exception

           Code Smell
        398. Field names should comply with a naming convention

           Code Smell
        399. Primitive wrappers should not be instantiated only for "toString" or "compareTo" calls

           Code Smell
        400. Case insensitive string comparisons should be made without intermediate upper or lower casing

           Code Smell
        401. "Collection.isEmpty()" should be used to test for emptiness

           Code Smell
        402. "String.valueOf()" should not be appended to a "String"

           Code Smell
        403. "switch case" clauses should not have too many lines of code

           Code Smell
        404. "Enumeration" should not be implemented

           Code Smell
        405. Constant names should comply with a naming convention

           Code Smell
        406. Synchronized classes "Vector", "Hashtable", "Stack" and "StringBuffer" should not be used

           Code Smell
        407. Exit methods should not be called

           Code Smell
        408. Unused "private" methods should be removed

           Code Smell
        409. Methods should not have too many return statements

           Code Smell
        410. Try-catch blocks should not be nested

           Code Smell
        411. Interface names should comply with a naming convention

           Code Smell
        412. Track uses of "TODO" tags

           Code Smell
        413. Track uses of "FIXME" tags

           Code Smell
        414. Deprecated code should be removed

           Code Smell
        415. Strings literals should be placed on the left side when checking for equality

           Code Smell
        416. Exceptions in "throws" clauses should not be superfluous

           Code Smell
        417. Files should end with a newline

           Code Smell
        418. Unnecessary imports should be removed

           Code Smell
        419. Return of boolean expressions should not be wrapped into an "if-then-else" statement

           Code Smell
        420. Boolean literals should not be redundant

           Code Smell
        421. Modifiers should be declared in the correct order

           Code Smell
        422. Deprecated elements should have both the annotation and the Javadoc tag

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

           Code Smell
        424. Source code should be indented consistently

           Code Smell
        425. Generic exceptions should never be thrown

           Code Smell
        426. Labels should not be used

           Code Smell
        427. Utility classes should not have public constructors

           Code Smell
        428. Local variables should not shadow class fields

           Code Smell
        429. Empty statements should be removed

           Code Smell
        430. The "Object.finalize()" method should not be overridden

           Code Smell
        431. Redundant pairs of parentheses should be removed

           Code Smell
        432. A close curly brace should be located at the beginning of a line

           Code Smell
        433. Close curly brace and the next "else", "catch" and "finally" keywords should be on two different lines

           Code Smell
        434. Close curly brace and the next "else", "catch" and "finally" keywords should be located on the same line

           Code Smell
        435. An open curly brace should be located at the beginning of a line

           Code Smell
        436. An open curly brace should be located at the end of a line

           Code Smell
        437. Class variable fields should not have public accessibility

           Code Smell
        438. Inheritance tree of classes should not be too deep

           Code Smell
        439. Magic numbers should not be used

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

           Code Smell
        441. URIs should not be hardcoded

           Code Smell
        442. Methods should not have too many parameters

           Code Smell
        443. Unused "private" fields should be removed

           Code Smell
        444. Expressions should not be too complex

           Code Smell
        445. Mergeable "if" statements should be combined

           Code Smell
        446. Unused labels should be removed

           Code Smell
        447. Standard outputs should not be used directly to log anything

           Code Smell
        448. Tabulation characters should not be used

           Code Smell
        449. Files should not have too many lines of code

           Code Smell
        450. Lines should not be too long

           Code Smell
        451. Class names should comply with a naming convention

           Code Smell
        452. Method names should comply with a naming convention

           Code Smell

        Method names should comply with a naming convention

        consistency - identifiable
        maintainability
        Code Smell
        • convention

        Why is this an issue?

        Shared naming conventions allow teams to collaborate efficiently.

        This rule raises an issue when a method name does not match a provided regular expression.

        For example, with the default provided regular expression ^[a-z][a-zA-Z0-9]*$, the method:

        public int DoSomething(){...} // Noncompliant
        

        should be renamed to

        public int doSomething(){...}
        

        Exceptions

        Overriding methods are excluded.

        @Override
        public int Do_Something(){...} // Compliant by exception
        
          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