GoogleNonConstantFieldName
Since Checkstyle 13.1.0
Description
Checks that non-constant field names conform to the
Google Java Style Guide for non-constant field naming.
This check enforces Google's specific non-constant field naming requirements:
- Non-constant field names must start with a lowercase letter and use uppercase letters for word boundaries.
- Underscores may be used to separate adjacent numbers (e.g., version
numbers like
guava33_4_5), but NOT between letters and digits.
Static fields are skipped because Checkstyle cannot determine type immutability to distinguish constants from non-constants.
Examples
To configure the check:
<module name="Checker">
<module name="TreeWalker">
<module name="GoogleNonConstantFieldName"/>
</module>
</module>
Code Example:
class Example1 {
int fooBar;
int guava33_4_5;
int httpClient;
int version1_2;
int Foo;
// violation above, ''Foo' must start with a lowercase letter'
int f;
// violation above, ''f' must start with a lowercase letter, min 2 chars'
int gradle_9_5_1;
// violation above, ''gradle_9_5_1' has invalid underscore usage'
int foo_bar;
// violation above, ''foo_bar' has invalid underscore usage'
}
Example of Usage
Violation Messages
All messages can be customized if the default message doesn't suit you. Please see the documentation to learn how to.
Package
com.puppycrawl.tools.checkstyle.checks.naming






