rspec/rules/S2207/java/rule.adoc
2021-04-28 18:08:03 +02:00

54 lines
953 B
Plaintext

Including any logic other than a simple return of the field in a persistence-annotated method can result in odd behavior, including for example, the default construction of empty members which are annotated to be ``++lazy++``.
== Noncompliant Code Example
----
private Double price;
@Columm(name="price")
public Double getPrice() {
if(buyer.isLoaltyMember()) { // Noncompliant
return price - getLoyaltyDiscount();
} else {
return price;
}
}
----
== Compliant Solution
----
@Columm(name="price")
private Double price;
public Double getPrice() {
if(buyer.isLoaltyMember()) {
return price - getLoyaltyDiscount();
} else {
return price;
}
}
----
or
----
private Double price;
@Columm(name="price")
public Double getPrice() {
return price;
}
public Double calculatePrice() {
if(buyer.isLoaltyMember()) { // Noncompliant
return getPrice() - getLoyaltyDiscount();
} else {
return getPrice();
}
}
----