ConstantNaming
WARNING
Style
Summary
Constant variables should adhere to the
UPPER_SNAKE_CASE
naming convention
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("ConstantNaming")
to the enclosing element.Disable this pattern completely by adding
-Xep:ConstantNaming:OFF
as compiler argument. Learn more.
Samples
Replacement
Shows the difference in example code before and after the bug pattern is applied.
class A {
static final int foo = 1;
- private static final int bar = 2;
+ private static final int BAR = 2;
private static final int baz = 3;
private static final int BAZ = 4;
}
Identification
Shows code lines which will (not) be flagged by this bug pattern.
A //BUG: Diagnostic contains:
comment is placed above any violating line.
class A {
private static final long serialVersionUID = 1L;
private static final int FOO = 1;
// BUG: Diagnostic contains: consider renaming to 'BAR', though note that this is not a private
// constant
static final int bar = 2;
// BUG: Diagnostic contains:
private static final int baz = 3;
// BUG: Diagnostic contains: consider renaming to 'QUX_QUUX', though note that a variable with
// this name is already declared
private static final int qux_QUUX = 4;
// BUG: Diagnostic contains: consider renaming to 'QUUZ', though note that a variable with
// this name is already declared
private static final int quuz = 3;
private final int foo = 4;
private final Runnable QUX_QUUX =
new Runnable() {
private static final int QUUZ = 1;
@Override
public void run() {}
};
}
class A {
private static final long serialVersionUID = 1L;
private static final int foo = 1;
// BUG: Diagnostic contains:
private static final int bar = 2;
private static final int baz = 3;
}