ThrowsCount simply counts the number of declared
exceptions of a method, and adds an audit entry if this
number exceeds the configured maximum.
However, the rationale is to encourage a coding style
where exceptions are part of a class hierarchy.
ThrowsCount does not consider exception hierarchies.
Instead of counting the number of declared exceptions,
it should count the number of common ancestor classes
of the declared exceptions that are direct children of
java.lang.Exception and only create an audit entry if the
number of such ancestors exceed the configured
I attached an example that demonstrates the problem.
Let's configure the check like so:
<property name="max" value="2"/>
Now consider this method:
public void testThrowsCount() throws ExceptionX,
It declares to throw three exceptions. However,
ExceptionX and ExceptionY have the common parent
class AbstractException. Thus there are only two
common ancestors that are directly derived from
java.lang.Exception - specifically
test.throwscount.AbstractException. No audit entry
should be created.
The way ThrowsCount is implemented right now, the
method would need to declare to throw
AbstractException which then would have to be caught
explicitly. That is precisely what we do not want.
Log in to post a comment.