Why FortEE - Pscheidl/FortEE GitHub Wiki
Main goal of FortEE is to make it easy to create "fortified points" in code, where methods either return a desired value or they do not. Nothing else.
FortEE makes sure any Throwable will not get past methods guarded by it's interceptors, unless explicitly specified. With FortEE, erroneous states are
- Safely catched and handled in a separate channel with a unified logic
- Converted into an empty Optional.
FortEE provides a startup-time safety of annotated methods having the right Optional return type.
Non-trivial projects often consist of multiple application layers. Such layers may be more or less mutually dependent. As layers call each other, exceptional and erroneous states appear. In Java world, these are represented by Throwable interface. There are two basic subtypes of Throwables, unchecked Errors and checked Exceptions.
FortEE does not only prevent unchecked exceptions (subclasses of Error) from interrupting other layers of an application, it works with silently thrown checked exceptions. By default, it is required for every checked exception thrown to be declared in "throws" block of a method, forcing callers to handle the potential exceptional state or pass the exception on. However, there is a way in Java to silently fire checked exceptions, evading javac's compile-time checks. One of the popular ways to do it is to use ExceptionUtils from the Apache Commons Lang 3 library.
Such behavior can be seen in one of FortEE's test beans, where checked IOException is silently thrown without any need to introduce a "throws" block.
The malicious code looks like this.
public Optional<String> convertSilentException() {
return ExceptionUtils.rethrow(new IOException());
}
However, standard way to throw checked exceptions is as follows.
public Optional<String> convertSilentException() throws IOException {
throw new IOException();
}
But there is no guarantee a library used or another developer's code does not involve unchecked or silently fired exceptions. For this reason, FortEE catches any instance of any subclass of Throwable and does not limit itself to unchecked exceptions.