rspec/rules/S1190/java/rule.adoc

73 lines
1.9 KiB
Plaintext

== Why is this an issue?
Programming languages evolve over time, and new versions of Java introduce additional keywords.
If future keywords are used in the current code, it can create compatibility issues when transitioning to newer versions of Java.
The code may fail to compile or behave unexpectedly due to conflicts with newly introduced keywords.
The `\_` keyword was deprecated in Java 9 and disallowed since Java 11. Starting from Java 22 the `_` was introduced as `unnamed variable`.
This rule reports an issue when `_` is used in versions prior to Java 22.
== How to fix it
Rename the `_` identifiers.
=== Code examples
==== Noncompliant code example
[source,java,diff-id=1,diff-type=noncompliant]
----
public class MyClass {
String _ = ""; // Noncompliant
}
----
==== Compliant solution
[source,java,diff-id=1,diff-type=compliant]
----
public class MyClass {
String s = ""; // Compliant
}
----
== Resources
=== Documentation
* https://docs.oracle.com/en/java/javase/22/docs/specs/unnamed-jls.html#jls-3.9[Oracle - Unnamed Variables and Patterns Keywords]
* https://docs.oracle.com/en/java/javase/22/language/unnamed-variables-and-patterns.html[Oracle - Unnamed Variables and Patterns]
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Rename this variable to something other than "XXX", which is a Java keyword.
'''
== Comments And Links
(visible only on this page)
=== is duplicated by: S3859
=== relates to: S1669
=== relates to: S2306
=== is related to: S1527
=== is related to: S1189
=== on 8 Aug 2013, 16:32:59 Freddy Mallet wrote:
Is implemented by \http://jira.codehaus.org/browse/SONARJAVA-280
=== on 13 Aug 2019, 10:18:47 Michael Gumowski wrote:
Removing reference to JIRA ticket in rule description. See SONARJAVA-285 and SONARJAVA-3179 for rule limitation.
endif::env-github,rspecator-view[]