Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Map in a serializable class is shown as Sonar violation when explicitly initialized with null

I am using SonarQube 6.7.3 with Sonar java plugin 5.3

I have a Serializable java class with a map as an instance variable. 1. Map is showing S1948 rule violation when initialized with null explicitly. 2. Map is not showing any violation when that explicit null initialization is removed.

Same can be seen below screenshot. Can you help me understand the difference between the two.

Screen shot: enter image description here

like image 627
arkay Avatar asked Oct 16 '25 07:10

arkay


1 Answers

Some implementations of Map are serializable, others are not. So if you initialize it as a null, it will raise the rule as Sonar doesn't have a way to know what implementation you're going to use.

This post has it all explained: Java why a Map of Map (ex: Map<String,Map<String,String>>) not serializeable

like image 82
brunags Avatar answered Oct 18 '25 21:10

brunags



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!