0

While for below Code we are getting error in sonar:

 entityBuilderMap = Maps.newHashMap(); 

Giving error in sonar as:

Dodgy - Write to static field from instance method

Can some one suggest how to fixed it out

acostela
  • 2,597
  • 3
  • 33
  • 50

1 Answers1

0

Assigning to a Static variable a value from an instance is a bad design practice. This can lead you in te future to bugs and problems. As a programmer we expect that static methods assign static values. If we have two different instances that assign that value as a programmer you will think that instances are changing different values but it's the same. This is very dangerous.

You can read a long description about in this SO thread.

Writing to a static variable in an instance method, why is this a bad practice?

Community
  • 1
  • 1
acostela
  • 2,597
  • 3
  • 33
  • 50