2023-05-03 11:06:20 +02:00
== Why is this an issue?
2020-12-21 15:38:52 +01:00
There is no reason to store a value that is never read. Doing so indicates a bug: was the value assigned to the wrong variable? Was some calculation left out of the method? If it is not a bug, it is a waste of cycles and an obfuscation of the code.
2023-05-03 11:06:20 +02:00
=== Noncompliant code example
2020-12-21 15:38:52 +01:00
2022-02-04 17:28:24 +01:00
[source,text]
2020-12-21 15:38:52 +01:00
----
public int getNumber(int a) {
int i;
int b = a;
for (i = 0; i < 10; i++) {
b *= i;
}
i = a; // Noncompliant; value assigned but not used before return
return b;
}
----
2023-05-03 11:06:20 +02:00
=== Compliant solution
2020-12-21 15:38:52 +01:00
2022-02-04 17:28:24 +01:00
[source,text]
2020-12-21 15:38:52 +01:00
----
public int getNumber(int a) {
int i;
int b = a;
for (i = 0; i < 10; i++) {
b *= i;
}
return b;
}
----
2022-01-25 18:36:46 +01:00
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
2023-05-25 14:18:12 +02:00
=== Message
Remove this useless assignment of "xxx".
2022-01-25 18:36:46 +01:00
'''
== Comments And Links
(visible only on this page)
2023-05-25 14:18:12 +02:00
=== on 10 Oct 2014, 14:05:08 Freddy Mallet wrote:
@Ann, for me this RSPEC duplicates RSPEC-1981
2022-01-25 18:36:46 +01:00
endif::env-github,rspecator-view[]