Rule Definition
Using 'synchronized' qualifier for EJB methods or calling 'wait', 'notify' and 'notifyAll' from EJB methods might corrupt the normal behavior of the application server
Remediation
Review EJB design
Violation Code Sample
@Entity public class Customer implements Serializable { private String id; private String firstName; private String lastName; private Address address; public Customer() {...} public Customer(String id, String firstName, String lastName) {...} @Id public String getCustomerId() {...} public synchronized void setCustomerId(String id) {...} public String getFirstName() {...} public synchronized void setFirstName(String firstName) {...} public String getLastName() {...} public synchronized void setLastName(String lastName) {...} @OneToOne() public Address getAddress() {...} public synchronized void setAddress(Address address) {...} } The use of synchronized methods violate the restriction of the EJB specification against the use synchronization primitives within EJBs. This may cause inconsistent behavior of the EJB when used within different EJB containers.
Fixed Code Sample
@Entity public class Customer implements Serializable { private String id; private String firstName; private String lastName; private Address address; public Customer() {...} public Customer(String id, String firstName, String lastName) {...} @Id public String getCustomerId() {...} public void setCustomerId(String id) {...} public String getFirstName() {...} public void setFirstName(String firstName) {...} public String getLastName() {...} public void setLastName(String lastName) {...} @OneToOne() public Address getAddress() {...} public void setAddress(Address address) {...} }
Reference
https://cwe.mitre.org/data/definitions/574.html
Related Technologies
JEE
Technical Criterion
Programming Practices - Unexpected Behavior
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.