Preventing Resource Leaks

As i’m unable to create custom rules on SonarCloud, I would like to know if the below Rule does exist in SonarCloud and if not perhaps this could be created.

Rule 1
Rule Name: “Implicitly Leaving Database Connections Open” OR “WARNING: Connection left open! (Please use DatabaseHelper.cleanUp method)”


This rule focuses on identifying potential resource leaks in Java code related to database connections and warns developers about code that might leave database connections open after using them. It achieves this by searching for specific patterns. For example:

  • oracleCallableStatement.execute(): Identifies code using Oracle Callable Statements for database operations.
  • Imported Classes: Checks if classes for OracleCallableStatement, ResultSet, or Connection are imported (indicating database interaction).
  • Missing Cleanup: Looks for the absence of a call to DatabaseHelper.cleanUp (or any other method responsible for closing resources) within a try block or a finally block that doesn’t explicitly set finally=‘false’.
  • Package Exclusion: Ignores code within specific packages if defined.

What it’s trying to achieve:

  • Prevent database connection leaks. Leaving connections open can:
    • Exhaust database connection pool resources.
    • Lead to performance issues on the database server.
    • Potentially create security vulnerabilities.

Rule 2
Rule Name: Do not put passwords into the contract


This rule aims to prevent passwords from being stored directly within your JSON files. It achieves this by searching for elements with names containing “password” (case-insensitive) anywhere within the file.

What it’s trying to achieve:

  • Enhance security by preventing sensitive information like passwords from being accidentally committed to version control systems.

Hey there.

For Rule 1, I think you’re looking for S2095: Resources should be closed.

Sonar doesn’t directly scan JSON files for the element “password” – but it does detect a number of specific secrets in all kinds of files (including JSON).