Sonar

add property "closeTargets" for CloseResource pmd rule

Details

  • Type: Improvement Improvement
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: 1.7
  • Fix Version/s: 1.9
  • Component/s: Rules
  • Labels:
    None
  • Environment:
    Linux, sonar 1.7
  • Number of attachments :
    0

Description

In PMD, for the rule CloseResource there is a "hidden" property (not documented) named closeTargets. It allow you to close a database connexion by using a database manager for exemple. If this property is not set, you can have a lot of false positive error.

see line 47 : http://pmd.svn.sourceforge.net/viewvc/pmd/tags/pmd/pmd_release_4_2_4/src/net/sourceforge/pmd/rules/CloseResource.java?view=markup

Activity

Hide
Freddy Mallet added a comment -

Thanks a lot Nicolas for this notification ! I was finding myself this rule very useless without this hidden property.

Show
Freddy Mallet added a comment - Thanks a lot Nicolas for this notification ! I was finding myself this rule very useless without this hidden property.
Hide
Simon Brandhof added a comment -

Hi Nicolas, unfortunately the property does not work for me. The bug seems to come from line 105 that looks for '.close' pattern.
Here is a screenshot of my results when I set closeTargets to 'close,stop' and types to 'Connection,StopableResource' : http://skitch.com/simon.brandhof/bceen/sonar-767. The objet resource is correctly closed.

Show
Simon Brandhof added a comment - Hi Nicolas, unfortunately the property does not work for me. The bug seems to come from line 105 that looks for '.close' pattern. Here is a screenshot of my results when I set closeTargets to 'close,stop' and types to 'Connection,StopableResource' : http://skitch.com/simon.brandhof/bceen/sonar-767. The objet resource is correctly closed.
Hide
Nicolas Dordet added a comment -

When I'm using PMD in SONAR the property "CloseTargets" DOESN'T WORK and I have some false positive. But when I'm using the property in PMD alone (with maven) IT WORKS.

here's my ruleset's configuration :
<properties>
<property name="types" value="Connection,Statement,ResultSet"/>
<property name="closeTargets" value="gbdd.fermer"/>
</properties>

the call to indirerctly close the connexion in the class targeted :
gbdd.fermer(resultSet);

and the method that really close the connexion :
public void fermer(final ResultSet resultSet) throws AccesBDDETException
{
if (resultSet != null)
{
try

{ resultSet.close(); }

...

Show
Nicolas Dordet added a comment - When I'm using PMD in SONAR the property "CloseTargets" DOESN'T WORK and I have some false positive. But when I'm using the property in PMD alone (with maven) IT WORKS. here's my ruleset's configuration : <properties> <property name="types" value="Connection,Statement,ResultSet"/> <property name="closeTargets" value="gbdd.fermer"/> </properties> the call to indirerctly close the connexion in the class targeted : gbdd.fermer(resultSet); and the method that really close the connexion : public void fermer(final ResultSet resultSet) throws AccesBDDETException { if (resultSet != null) { try { resultSet.close(); } ...
Hide
Simon Brandhof added a comment -

OK, thanks for the explanations.

Some integration tests have been added to check these classes.

Only classes ResourceIsNotClosed and ConnectionIsNotClosed should fail when the rule is activated with the following parameters :

  • types : Connection,CloseableResource
  • closeTargets : close,closeSilently
Show
Simon Brandhof added a comment - OK, thanks for the explanations. Some integration tests have been added to check these classes. Only classes ResourceIsNotClosed and ConnectionIsNotClosed should fail when the rule is activated with the following parameters :
  • types : Connection,CloseableResource
  • closeTargets : close,closeSilently
Hide
Nicolas Dordet added a comment -

Thanks for the rapidity of your reply !

Show
Nicolas Dordet added a comment - Thanks for the rapidity of your reply !

People

Vote (1)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: