On SonarCloud, we scanned the following code:
try (var connection = dataSource.getConnection().prepareStatement("...")) {
...
This (obviously) does not close the connection acquired via getConnection(). I assume Sonar did not discover this because it is not assigned to a variable.
compliant code:
public Long getNextValue() {
try (var connection = dataSource.getConnection();
var preparedStatement = connection.prepareStatement("...")) {
...
I would have expected this to cause S2095 (Resources should be closed)