2023-05-03 11:06:20 +02:00
|
|
|
== Why is this an issue?
|
|
|
|
|
2020-06-30 12:49:37 +02:00
|
|
|
include::description.adoc[]
|
|
|
|
|
2023-05-25 14:18:12 +02:00
|
|
|
=== Noncompliant code example
|
|
|
|
|
|
|
|
[source,text]
|
|
|
|
----
|
|
|
|
class A {
|
|
|
|
private int x;
|
|
|
|
private int y;
|
|
|
|
|
|
|
|
public void setX(int val) { // Noncompliant: field 'x' is not updated
|
|
|
|
this.y = val;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getY() { // Noncompliant: field 'y' is not used in the return value
|
|
|
|
return this.x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
----
|
|
|
|
|
|
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
|
|
|
|
[source,text]
|
|
|
|
----
|
|
|
|
class A {
|
|
|
|
private int x;
|
|
|
|
private int y;
|
|
|
|
|
|
|
|
public void setX(int val) {
|
|
|
|
this.x = val;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getY() {
|
|
|
|
return this.y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
----
|
2020-06-30 12:49:37 +02:00
|
|
|
|