66 lines
1.1 KiB
Plaintext
66 lines
1.1 KiB
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
|
|
|
|
[source,java]
|
|
----
|
|
private Double price;
|
|
|
|
@Columm(name="price")
|
|
public Double getPrice() {
|
|
if(buyer.isLoaltyMember()) { // Noncompliant
|
|
return price - getLoyaltyDiscount();
|
|
} else {
|
|
return price;
|
|
}
|
|
}
|
|
----
|
|
|
|
|
|
== Compliant Solution
|
|
|
|
[source,java]
|
|
----
|
|
@Columm(name="price")
|
|
private Double price;
|
|
|
|
public Double getPrice() {
|
|
if(buyer.isLoaltyMember()) {
|
|
return price - getLoyaltyDiscount();
|
|
} else {
|
|
return price;
|
|
}
|
|
}
|
|
----
|
|
or
|
|
|
|
[source,java]
|
|
----
|
|
private Double price;
|
|
|
|
@Columm(name="price")
|
|
public Double getPrice() {
|
|
return price;
|
|
}
|
|
|
|
public Double calculatePrice() {
|
|
if(buyer.isLoaltyMember()) { // Noncompliant
|
|
return getPrice() - getLoyaltyDiscount();
|
|
} else {
|
|
return getPrice();
|
|
}
|
|
}
|
|
----
|
|
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
include::message.adoc[]
|
|
|
|
endif::env-github,rspecator-view[]
|