SONAR complaining about Make the enclosing method "static" or remove this set

To be specific, you appear to be asking about rule S2696, 'Instance methods should not write to "static" fields'

As the rule description details:

Correctly updating a static field from a non-static method is tricky to get right and could easily lead to bugs if there are multiple class instances and/or multiple threads in play. Ideally, static fields are only updated from synchronized static methods.

Thus, the issue is telling you to make the method on which it was raised (presumably setApplicationContext) static, so that across all class instances there is only one copy of that method making updates to the static (i.e. shared across all class instances) field applicationContext. It additionally recommends making the method synchronized so that only one instance at a time can call the method.

Late edit: To see the rule description click either the "See Rule" or the "..." (depending on your version of SonarQube) shown after the issue message.


For what it's worth, and I'm probably going to get blacklisted by the Sonar community specifically and the Java Universe in general for saying this, adding @SuppressWarnings("squid:S2696") to the top of the offending method causes Sonar to ignore that warning completely.