CWE-574 EJB不安全实践:使用同步原语
EJB Bad Practices: Use of Synchronization Primitives
结构: Simple
Abstraction: Variant
状态: Draft
被利用可能性: unkown
基本描述
The program violates the Enterprise JavaBeans (EJB) specification by using thread synchronization primitives.
扩展描述
The Enterprise JavaBeans specification requires that every bean provider follow a set of programming guidelines designed to ensure that the bean will be portable and behave consistently in any EJB container. In this case, the program violates the following EJB guideline: "An enterprise bean must not use thread synchronization primitives to synchronize execution of multiple instances." The specification justifies this requirement in the following way: "This rule is required to ensure consistent runtime semantics because while some EJB containers may use a single JVM to execute all enterprise bean's instances, others may distribute the instances across multiple JVMs."
相关缺陷
-
cwe_Nature: ChildOf cwe_CWE_ID: 695 cwe_View_ID: 699
-
cwe_Nature: ChildOf cwe_CWE_ID: 821 cwe_View_ID: 1000 cwe_Ordinal: Primary
-
cwe_Nature: ChildOf cwe_CWE_ID: 821 cwe_View_ID: 699 cwe_Ordinal: Primary
适用平台
Language: {'cwe_Name': 'Java', 'cwe_Prevalence': 'Undetermined'}
常见的影响
范围 | 影响 | 注释 |
---|---|---|
Other | Quality Degradation |
可能的缓解方案
Implementation
策略:
Do not use Synchronization Primitives when writing EJBs.
示例代码
例
In the following Java example a Customer Entity EJB provides access to customer information in a database for a business application.
bad Java
public class Customer implements Serializable {
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) {...}
}
However, the customer entity EJB uses the synchronized keyword for the set methods to attempt to provide thread safe synchronization for the member variables. The use of synchronized methods violate the restriction of the EJB specification against the use synchronization primitives within EJBs. Using synchronization primitives may cause inconsistent behavior of the EJB when used within different EJB containers.
分类映射
映射的分类名 | ImNode ID | Fit | Mapped Node Name |
---|---|---|---|
Software Fault Patterns | SFP3 | Use of an improper API |
文章来源于互联网:scap中文网
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论