2023-10-13 12:26:37 +02:00
|
|
|
include::../why.adoc[]
|
2023-05-03 11:06:20 +02:00
|
|
|
|
2023-10-13 12:26:37 +02:00
|
|
|
=== Exceptions
|
2021-09-21 15:40:35 +02:00
|
|
|
|
2023-10-13 12:26:37 +02:00
|
|
|
This rule ignores initializations to `-1`, `0`, `1`, `null`, `true`, `false` and `""`.
|
2021-09-21 15:40:35 +02:00
|
|
|
|
2023-10-13 12:26:37 +02:00
|
|
|
include::../howtofixit.adoc[]
|
2021-09-21 15:40:35 +02:00
|
|
|
|
2023-10-13 12:26:37 +02:00
|
|
|
=== Code examples
|
2021-09-21 15:40:35 +02:00
|
|
|
|
2023-10-13 12:26:37 +02:00
|
|
|
==== Noncompliant code example
|
2021-09-21 15:40:35 +02:00
|
|
|
|
2023-10-13 12:26:37 +02:00
|
|
|
[source,java,diff-id=1,diff-type=noncompliant]
|
|
|
|
----
|
|
|
|
int foo(int y) {
|
|
|
|
int x = 100; // Noncompliant: dead store
|
|
|
|
x = 150; // Noncompliant: dead store
|
|
|
|
x = 200;
|
|
|
|
return x + y;
|
|
|
|
}
|
|
|
|
----
|
|
|
|
|
|
|
|
==== Compliant solution
|
|
|
|
|
|
|
|
[source,java,diff-id=1,diff-type=compliant]
|
|
|
|
----
|
|
|
|
int foo(int y) {
|
|
|
|
int x = 200; // Compliant: no unnecessary assignment
|
|
|
|
return x + y;
|
|
|
|
}
|
|
|
|
----
|
|
|
|
|
|
|
|
include::../see.adoc[]
|
|
|
|
|
|
|
|
=== Related rules
|
|
|
|
|
|
|
|
* S2583 - Conditionally executed code should be reachable
|
|
|
|
* S2589 - Boolean expressions should not be gratuitous
|
|
|
|
* S3516 - Methods returns should not be invariant
|
|
|
|
* S3626 - Jump statements should not be redundant
|
2021-06-02 20:44:38 +02:00
|
|
|
|
2021-06-03 09:05:38 +02:00
|
|
|
ifdef::env-github,rspecator-view[]
|
2021-09-20 15:38:42 +02:00
|
|
|
|
|
|
|
'''
|
|
|
|
== Implementation Specification
|
|
|
|
(visible only on this page)
|
|
|
|
|
|
|
|
include::../message.adoc[]
|
|
|
|
|
2021-06-08 15:52:13 +02:00
|
|
|
'''
|
2021-06-02 20:44:38 +02:00
|
|
|
== Comments And Links
|
|
|
|
(visible only on this page)
|
|
|
|
|
|
|
|
include::../comments-and-links.adoc[]
|
2023-06-22 10:38:01 +02:00
|
|
|
|
2021-06-03 09:05:38 +02:00
|
|
|
endif::env-github,rspecator-view[]
|