Is there some other annotation I need to use to avoid the warning when my code goes through static analysis?
You can just use the
@SuppressWarning annotation. By convention, we include a comment to say why.
For example, I have this in some of my code where the class represents data that I get back from SendGrid:
@SuppressWarnings('PMD.VariableNamingConventions') // We have to use the names chosen by SendGrid
So, I guess you would use something like
I'm not entirely sure I've got the name right there, but you can get it from the message PMD gives you. I switch that rule off entirely via my xml ruleset because we use a lot of globals to communicate with a generic utils package we have.
Your use case needs you to expose a web service. A web service should be always global. I wont worrry much about that warning, as its informative more than obstructing your work. That being said you can change that rule.
The source code of that rule is present here: https://github.com/pmd/pmd/blob/master/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/bestpractices/AvoidGlobalModifierRule.java
You can alter that rule's java file to not trigger if class contains
Meanwhile, I have submitted it as an issue to PMD. Src: https://github.com/pmd/pmd/issues/1348
Edit : The above issue is fixed by PMD devs and the newest version you will download wil have it encorporated. No need to silence PMD rule now. Src: https://github.com/pmd/pmd/pull/1353