Define separate interfaces for local and remote Enterprise JavaBeans (EJB)

An interface cannot be local and remote at the same time. However, you can define all methods in a single interface, and then extend the interface to create separate local and remote interfaces that you can reference on annotations or elements.

This rule flags interfaces that are used on both the javax.ejb.Local and javax.ejb.Remote annotations on the same class. It also flags business-local and business-remote elements that reference the same interface within the same session element in the ejb-jar.xml file.

In the following Java code, the reference to MyInterface.class is flagged on the javax.ejb.Local and javax.ejb.Remote annotations.

public interface MyInterface () { .. }

@Stateless(name="MyEJB")
@Remote(MyInterface.class)
@Local(MyInterface.class)
public final class MyEJB implements MyInterface {
    ...
}

In the following ejb-jar.xml file, the business-local and business-remote elements are flagged by this rule.

<session>
    <ejb-name>MyEJB</ejb-name>
    <business-local>com.ibm.sample.MyInterface</business-local>
    <business-remote>com.ibm.sample.MyInterface</business-remote>
    <ejb-class>com.ibm.sample.MyEJB</ejb-class>
    <session-typegt;Stateless</session-type>
    <transaction-typegt;Container</transaction-type>
 </session>

To resolve this issue, extend the interface to create separate local and remote interfaces, and reference them on the annotations or elements:

public interface MyInterfaceLocal extends MyInterface() 
{ .. }
public interface MyInterfaceRemote extends MyInterface() 
{ .. }