Reputation: 5867
I have seen the link before asking question here, I wonder why SONAR complaining only arrays and not custom objects.
Because same problem can occur in the custom objects we declare in the bean as well. And also, i couldnt agree why we need to take copy as we like to modify the same array that's why we have setters and all correct?
Kindly help me to understand, SONAR is showing more number of violations in this category.
Upvotes: 0
Views: 514
Reputation: 15792
Sharing mutable state should be avoided since it can cause error in your program. Especially if you are working in multi threaded environment. Also it can make you program much less readable. That's why communication throw modifying same state should be at least minimize.
Coping collections and arrays as well as dates are common practice to make sure that you don't use in your class/thread same object that was provided from other object/thread.
Upvotes: 1