EJB Bad Practices: Use of Java I/O

Draft Variant
Structure: Simple
Description

This vulnerability occurs when an Enterprise JavaBeans (EJB) component incorrectly uses Java I/O (java.io) operations to access the file system, violating the EJB specification's design principles.

Extended Description

The EJB specification explicitly prohibits the use of java.io package file system access within enterprise beans. This restriction exists because EJB components are designed as portable business logic units that should remain independent of the server's underlying file structure. Using standard file I/O ties your component to a specific server environment, breaking portability and creating inconsistent behavior across different EJB containers. Instead of file system access, EJB components should interact with data through managed resource APIs like JDBC for databases or JMS for messaging. These standardized interfaces ensure proper transaction management, security, and scalability within the container's managed environment. Following this practice maintains the component's portability and leverages the container's built-in services for reliable data handling.

Common Consequences 1
Scope: Other

Impact: Quality Degradation

Potential Mitigations 1
Phase: Implementation
Do not use Java I/O when writing EJBs.
Demonstrative Examples 1
The following Java example is a simple stateless Enterprise JavaBean that retrieves the interest rate for the number of points for a mortgage. In this example, the interest rates for various points are retrieved from an XML document on the local file system, and the EJB uses the Java I/O API to retrieve the XML document from the local file system.

Code Example:

Bad
Java
java

/* get XML document from the local filesystem / interestRateFile = new File(Constants.INTEREST_RATE_FILE);

java
java
This use of the Java I/O API within any kind of Enterprise JavaBean violates the EJB specification by using the java.io package for accessing files within the local filesystem.
An Enterprise JavaBean should use a resource manager API for storing and accessing data. In the following example, the private member function getInterestRateFromXMLParser uses an XML parser API to retrieve the interest rates.

Code Example:

Good
Java
java

/* member function to retrieve interest rate from XML document using an XML parser API /

java
Applicable Platforms
Languages:
Java : Undetermined
Modes of Introduction
Implementation
Related Weaknesses
Taxonomy Mapping
  • Software Fault Patterns