Check for a behavior change in EJB application exception inheritance

Starting with the Java EE 6.0 specification, application exceptions are inherited by subclass exception classes by default. This behavior is configurable on the @ApplicationException annotation or in the <application-exception> element of an ejb-jar.xml file.

This rule flags the javax.ejb.ApplicationException annotation if it does not have a defined inherited attribute, and it flags the <application-exception> element in an ejb-jar.xml file that does not have a defined inherited element.


For example, the rule flags the following @ApplicationException annotation:
@ApplicationException(rollback = true)
public class ExceptionA extends Exception {
}

public class ExceptionB extends ExceptionA {
}

The rule also flags the <application-exception> element in a ejb-jar.xml in the following example:
<application-exception>
    <exception-class>ExceptionA</exception-class>
    <rollback>true</rollback>
</application-exception>


The exceptions in the ejb-jar.xml can be implemented in the application such as in the following example:
public class ExceptionA extends Exception {
}

public class ExceptionB extends ExceptionA {
}

In Java EE 5.0, ExceptionB is not considered an ApplicationException, but in Java EE 6.0 ExceptionB is an ApplicationException because it extends from the ExceptionA class. Java EE 6.0 added the inherited attribute with default value of true, so all inherited classes are also ApplicationException.

You can preserve the Java EE 5.0 behavior in the following ways:

For more information, see the following resources: