S2095 report on method return Connection

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

Hi,

I can’t reproduce this issue with latest version of sonarjava.
What are the fully qualified names of Connection and datasource in your code snippet ?
What version of sonarlint and sonarjava (if in connected mode) are you using ?

Thanks

Actually on latest issue isn’t reproducible