False positive for synchronized class Hashtable

347 views
Skip to first unread message

Cristiano Gavião

unread,
Jun 2, 2016, 4:26:02 PM6/2/16
to SonarLint
hello,

I'm getting this issue: Replace the synchronized class "Hashtable" by an unsynchronized one such as "HashMap" for the code bellow:

Dictionary<String, Object> allProperties = new Hashtable<>();

 
The API (OSGi) I'm working with uses Dictionary everywhere and there aren't any other implementation options for it.

also, HashMap doesn't even implements Dictionary interface, so I think this rule is wrong for this situation.

regards,

Cristiano

Nicolas Peru

unread,
Jun 3, 2016, 2:52:03 AM6/3/16
to Cristiano Gavião, SonarLint
Hi Cristiano, 

This is a remark on a java rule, I understand the issue on that rule in your context but I don't really see how we could actually detect the context of usage of hashtable within an OSGi API ? 
 Would you have a suggestion on this ? I am no OSGi expert. 
So : What could be indicators that instantiating a HashTable in this context is ok ?

In the meantime, my only suggestion would be to deactivate the rule.

Cheers, 

--
You received this message because you are subscribed to the Google Groups "SonarLint" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarlint+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarlint/fdb49ac0-baaa-4a09-ba61-835405874862%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
Nicolas PERU | SonarSource
Senior Developer
http://sonarsource.com

Cristiano Gavião

unread,
Jun 6, 2016, 1:30:27 PM6/6/16
to SonarLint, cvga...@gmail.com
Hello Nicolas,

Well, I have no clue how your tool does to detect things on code...

but certainly if the class under process have any org.osgi.* import clause on it, that will be enough to imply that it is in an OSGi context.
 
or also you may detect that the Dictionary attribute being created is being used as parameter for a outside method which accepts Dictionary... even outside an OSGi context to me doesn't make sense to generate an issue for that.

btw, how could you point me a place that tells me how to deactivate that rule?

thanks and best regards,

Cristiano 

Nicolas Peru

unread,
Jun 16, 2016, 2:43:40 AM6/16/16
to Cristiano Gavião, SonarLint
Hi Cristiano, 

I am afraid we wont' be able to do something in your specific case on the rule side. 
To deactivate the rule in sonarlint you need to bind your project to a SQ instance and configure a quality profile : http://docs.sonarqube.org/display/SONAR/Quality+Profiles 

Cheers, 


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