Checking string constants for banned characters

java

(Benjamin Kohler) #1

I am trying to check that strings passed to a method do not contain banned characters.

I can do this for String Literals, but I can’t figure out how to get the value from an IdentifierTree when it is a public static final String variable.

Any advice?

Thanks


(Nicolas Peru) #2

Short answer is : there is no API for that.

A bit more complex answer would be : we have done some effort in that direction that are not part of the API and on which you can get some inspiration (with no guarantee nor support) : have a look at ConstantUtils class in SonarJava source code.