Reserved Words in Identifiers
ID |
java.naming_reserved_words |
Severity |
info |
Remediation Complexity |
trivial |
Remediation Risk |
medium |
Remediation Effort |
low |
Resource |
Naming Convention |
Language |
Java |
Tags |
naming |
Description
Reports field and method names that are Java reserved words or future keywords. Using a reserved word as an identifier is confusing and may cause issues with tooling or future language versions.
Only exact matches are flagged. Identifiers that merely contain a reserved word as a substring (e.g., newValue, getClass) are fine.
|
Rationale
Java reserved words have special meaning in the language. Using them as identifiers (even when technically possible via reflection or code generation) confuses readers and tools. Future reserved words like var, yield, record, sealed, and permits should also be avoided as identifiers.
// Bad — identifier is a reserved word
int new = 5; // won't compile
String var = "x"; // compiles but confusing (var is a restricted identifier)
// Good — descriptive names
int count = 5;
String value = "x";
Remediation
Rename the identifier to a descriptive name that is not a Java reserved word or future keyword.