SQUID S2095 improvement

54 views
Skip to first unread message

Charles Morin

unread,
Jan 16, 2017, 11:08:25 AM1/16/17
to SonarQube
Hi,

Sonar rule #S2095 always expects a .close() call in the finally block. However, Java already has that overhead in place since Java 7+.

As per the ResultSet Javadoc:
A ResultSet object is automatically closed when the Statement object that generated it is closed, re-executed, or used to retrieve the next result from a sequence of multiple results.

Could it be possible to make the rule a little bit smarter so that overhead is taken into consideration?

API Docs :

Thank you

Charles

Tibor Blenessy

unread,
Jan 16, 2017, 1:07:50 PM1/16/17
to Charles Morin, SonarQube
Hello,

indeed that could be an useful extension of the rule. Can you please provide short code sample demonstrating the problem? Thanks.

Best regards

--
You received this message because you are subscribed to the Google Groups "SonarQube" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarqube+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/c7a5d306-78f1-4969-b3eb-002adda2f535%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
Tibor BLENESSY | SonarSource
Software Engineer

Charles Morin

unread,
Jan 16, 2017, 1:31:26 PM1/16/17
to SonarQube, charl...@gmail.com

Of course!

try (Connection connection = CommonTools.connectToDatasource();

     PreparedStatement statement = connection.prepareStatement("SELECT * FROM myschema.myfunction(?, ?, ?)");) {

    statement.setInt(1, siteId);

    statement.setDate(2, scheduleDate);

    statement.setInt(3, 4


    ResultSet resultSet = statement.executeQuery();


    while (resultSet.next()) {

       ...

    }

   
...

    resultSet.close();

} catch (Exception e) {

   ...
}


Tibor Blenessy

unread,
Jan 19, 2017, 5:54:32 AM1/19/17
to Charles Morin, SonarQube
Thank you for example, I created following JIRA ticket to handle the issue


Best regards


For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages