Pattern: Illegal token text
Issue: -
Checks specified tokens text for matching an illegal pattern from format
property.
By default Google Java Style Guide is applied: For any character that has a special escape sequence, that sequence should be used rather than the corresponding octal (e.g. \012
) or Unicode (e.g. \u000a
) escape.
<module name="IllegalTokenText">
<property name="tokens" value="STRING_LITERAL, CHAR_LITERAL"/>
<property name="format" value="\\u00(09|0(a|A)|0(c|C)|0(d|D)|22|27|5(C|c))|\\(0(10|11|12|14|15|42|47)|134)"/>
<property name="message" value="Consider using special escape sequence instead of octal value or Unicode escaped value."/>
</module>
Example of incorrect code:
string newLine = "\015\012";
Example of correct code:
string newLine = "\r\n";
To configure the check to forbid String literals containing "a href"
:
<module name="IllegalTokenText">
<property name="tokens" value="STRING_LITERAL"/>
<property name="format" value="a href"/>
</module>