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
 
Tags
    Impact
      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. @InitBinder methods should have void return type

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

           Code Smell
        21. @Cacheable and @CachePut should not be combined

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

           Code Smell
        23. Use appropriate @DirtiesContext modes

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

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

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

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

           Code Smell
        28. Motion Sensor should not use gyroscope

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

           Code Smell
        30. Use Fused Location to optimize battery power

           Code Smell
        31. Use batch Processing in JDBC

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

           Code Smell
        33. SQL queries should retrieve only necessary fields

           Code Smell
        34. Avoid using "FetchType.EAGER"

           Code Smell
        35. High frame rates should not be used

           Code Smell
        36. Exact alarms should not be abused

           Code Smell
        37. Proper Sensor Resource Management

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

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

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

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

           Code Smell
        42. Reverse iteration should utilize reversed view

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

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

           Code Smell
        45. Non-singleton Spring beans should not be injected into singleton beans

           Code Smell
        46. Bean names should adhere to the naming conventions

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

           Code Smell
        48. Optional REST parameters should have an object type

           Code Smell
        49. Field dependency injection should be avoided

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

           Code Smell
        51. "@Value" annotation should inject property or SpEL expression

           Code Smell
        52. Redundant nullability annotations should be removed

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

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

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

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

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

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

           Code Smell
        59. Superfluous curly brace quantifiers should be avoided

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

           Code Smell
        61. Deprecated annotations should include explanations

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

           Code Smell
        63. Regular expressions should not contain empty groups

           Code Smell
        64. Regular expressions should not contain multiple spaces

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

           Code Smell
        66. Lambdas should not invoke other lambdas synchronously

           Code Smell
        67. Consumer Builders should be used

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

           Code Smell
        91. Tests should be stable

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

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

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

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

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

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

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

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

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

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

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

           Code Smell
        103. Regular expressions should not be too complicated

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

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

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

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

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

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

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

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

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

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

           Code Smell
        114. Vararg method arguments should not be confusing

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

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

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

           Code Smell
        118. Lambdas should not have too many lines

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

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

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

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

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

           Code Smell
        124. Use Java 14 "switch" expression

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

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

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

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

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

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

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

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

           Code Smell
        133. Java features should be preferred to Guava

           Code Smell
        134. "StandardCharsets" constants should be preferred

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

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

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

           Code Smell
        138. "@EnableAutoConfiguration" should be fine-tuned

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

           Code Smell
        140. "default" clauses should be last

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

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

           Code Smell
        143. Nullness of parameters should be guaranteed

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

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

           Code Smell
        146. Spring components should use constructor injection

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

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

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

           Code Smell
        150. Regex patterns should not be created needlessly

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

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

           Code Smell
        153. Assignments should not be redundant

           Code Smell
        154. Methods should not have identical implementations

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

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

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

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

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

           Code Smell
        160. Collection contents should be used

           Code Smell
        161. Track uses of disallowed constructors

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

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

           Code Smell
        164. Conditionals should start on new lines

           Code Smell
        165. Number patterns should be regular

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

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

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

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

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

           Code Smell
        171. Members of Spring components should be injected

           Code Smell
        172. Raw types should not be used

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

           Code Smell
        174. Track uses of disallowed classes

           Code Smell
        175. Unit tests should throw exceptions

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

           Code Smell
        177. Jump statements should not be redundant

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

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

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

           Code Smell
        181. Methods returns should not be invariant

           Code Smell
        182. Format strings should be used correctly

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

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

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

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

           Code Smell
        187. Methods should not return constants

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

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

           Code Smell
        190. Ternary operators should not be nested

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

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

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

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

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

           Code Smell
        196. "StringBuilder" data should be used

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

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

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

           Code Smell
        200. Abstract methods should not be redundant

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

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

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

           Code Smell
        204. "ThreadGroup" should not be used

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

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

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

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

           Code Smell
        209. "clone" should not be overridden

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

           Code Smell
        211. Escaped Unicode characters should not be used

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

           Code Smell
        213. Assertions should be complete

           Code Smell
        214. Unnecessary semicolons should be omitted

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

           Code Smell
        216. JUnit rules should be used

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

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

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

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

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

           Code Smell
        222. Tests should include assertions

           Code Smell
        223. Test assertions should include messages

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

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

           Code Smell
        226. Threads should not be started in constructors

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

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

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

           Code Smell
        230. Method overrides should not change contracts

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

           Code Smell
        232. Boolean expressions should not be gratuitous

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

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

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

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

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

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

           Code Smell
        239. Unnecessary bit operations should not be performed

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

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

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

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

           Code Smell
        244. Redundant modifiers should not be used

           Code Smell
        245. Unused type parameters should be removed

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

           Code Smell
        247. Files should not be empty

           Code Smell
        248. "deleteOnExit" should not be used

           Code Smell
        249. Public methods should not contain selector arguments

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

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

           Code Smell
        252. Java parser failure

           Code Smell
        253. Track uses of disallowed methods

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

           Code Smell
        255. "IllegalMonitorStateException" should not be caught

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

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

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

           Code Smell
        259. Types should be used in lambdas

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

           Code Smell
        261. Wildcard imports should not be used

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

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

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

           Code Smell
        265. JUnit test cases should call super methods

           Code Smell
        266. TestCases should contain tests

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

           Code Smell
        268. Do not perform unnecessary mathematical operations

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

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

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

           Code Smell
        272. "finalize" should not set fields to "null"

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

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

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

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

           Code Smell
        277. Catches should be combined

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

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

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

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

           Code Smell
        282. Primitives should not be boxed just for "String" conversion

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

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

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

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

           Code Smell
        287. Classes should not be empty

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

           Code Smell
        289. Fields in non-serializable classes should not be "transient"

           Code Smell
        290. Comparators should be "Serializable"

           Code Smell
        291. "readResolve" methods should be inheritable

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

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

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

           Code Smell
        295. Member variable visibility should be specified

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

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

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

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

           Code Smell
        300. Simple class names should be used

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

           Code Smell
        302. Boolean checks should not be inverted

           Code Smell
        303. Extensions and implementations should not be redundant

           Code Smell
        304. Redundant casts should not be used

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

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

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

           Code Smell
        308. Unused assignments should be removed

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

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

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

           Code Smell
        312. Classes should not have too many fields

           Code Smell
        313. The ternary operator should not be used

           Code Smell
        314. Standard functional interfaces should not be redefined

           Code Smell
        315. Annotation repetitions should not be wrapped

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

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

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

           Code Smell
        319. "NullPointerException" should not be caught

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

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

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

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

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

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

           Code Smell
        326. Lambdas should be replaced with method references

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

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

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

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

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

           Code Smell
        332. Package declaration should match source file directory

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

           Code Smell
        334. Methods should not be too complex

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

           Code Smell
        336. Unused local variables should be removed

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

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

           Code Smell
        339. Track lack of copyright and license headers

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

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

           Code Smell
        342. Classes should not have too many methods

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

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

           Code Smell
        345. Methods should not have too many lines

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

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

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

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

           Code Smell
        350. Octal values should not be used

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

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

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

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

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

           Code Smell
        356. Track uses of "NOSONAR" comments

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

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

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

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

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

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

           Code Smell
        363. Track comments matching a regular expression

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

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

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

           Code Smell
        367. Statements should be on separate lines

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

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

           Code Smell
        370. Interfaces should not solely consist of constants

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

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

           Code Smell
        373. Control structures should use curly braces

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

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

           Code Smell
        376. Nested code blocks should not be used

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

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

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

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

           Code Smell
        381. String literals should not be duplicated

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

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

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

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

           Code Smell
        386. Methods should not be empty

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

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

           Code Smell
        389. Throwable and Error should not be caught

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

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

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

           Code Smell
        393. Unused method parameters should be removed

           Code Smell
        394. Only static class initializers should be used

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

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

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

           Code Smell
        398. Exception handlers should preserve the original exceptions

           Code Smell
        399. Exception classes should have final fields

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

           Code Smell
        401. Checked exceptions should not be thrown

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

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

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

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

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

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

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

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

           Code Smell
        410. "Enumeration" should not be implemented

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

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

           Code Smell
        413. Exit methods should not be called

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

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

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

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

           Code Smell
        418. Track uses of "TODO" tags

           Code Smell
        419. Track uses of "FIXME" tags

           Code Smell
        420. Deprecated code should be removed

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

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

           Code Smell
        423. Files should end with a newline

           Code Smell
        424. Unnecessary imports should be removed

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

           Code Smell
        426. Boolean literals should not be redundant

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

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

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

           Code Smell
        430. Source code should be indented consistently

           Code Smell
        431. Generic exceptions should never be thrown

           Code Smell
        432. Labels should not be used

           Code Smell
        433. Utility classes should not have public constructors

           Code Smell
        434. Local variables should not shadow class fields

           Code Smell
        435. Empty statements should be removed

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

           Code Smell
        437. Redundant pairs of parentheses should be removed

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

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

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

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

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

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

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

           Code Smell
        445. Magic numbers should not be used

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

           Code Smell
        447. URIs should not be hardcoded

           Code Smell
        448. Methods should not have too many parameters

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

           Code Smell
        450. Expressions should not be too complex

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

           Code Smell
        452. Unused labels should be removed

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

           Code Smell
        454. Tabulation characters should not be used

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

           Code Smell
        456. Lines should not be too long

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

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

           Code Smell

        "ResultSet.isLast()" should not be used

        intentionality - logical
        maintainability
        Code Smell
        • performance
        • pitfall
        • sql

        Why is this an issue?

        How can I fix it?

        More Info

        There are several reasons to avoid using this method:

        1. It is optionally available only for result sets of type ResultSet.TYPE_FORWARD_ONLY. Database drivers will throw an exception if not supported.
        2. The method can be expensive to execute as the database driver may need to fetch ahead one row to determine whether the current row is the last in the result set. The documentation of the method explicitly mentions this fact.
        3. What "the cursor is on the last row" means for an empty ResultSet is unclear. Database drivers may return true or false in this case .

        ResultSet.next() is a good alternative to ResultSet.isLast() as it does not have the mentioned issues. It is always supported and, as per specification, returns false for empty result sets.

          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