S2095 report on method return Connection

java
sonarlint

(ori marko) #1

Methods returning Connection object, still gets a S2095 warning

For example

public Connection getConnection() throws SQLException {
			
	Connection result = dataSource.getConnection();
	result.setAutoCommit(false);
	return result;
}

I want to return a Connection I can use, so I can’t close it in those methods.

Should there be a warning in such cases where connection should be left open?

Similar methods can be found in HikariConnectionProvider