Through Java's evolution keywords have been added. While code that uses those words as identifiers may be compilable under older versions of Java, it will not be under modern versions.

Following keywords are marked as invalid identifiers

Keyword Added
_ 9
enum 5.0

assert and strictfp are another example of valid identifiers which became keywords in later versions, however as documented in SONARJAVA-285, it is not easily possible to support parsing of the code for such old versions, therefore they are not supported by this rule.

Noncompliant Code Example

public void doSomething() {
  int enum = 42;            // Noncompliant
  String _ = "";   // Noncompliant
}

Compliant Solution

public void doSomething() {
  int magic = 42;
}