Filters duplicates of finally blocks that compiler generates.
To understand algorithm of filtering, consider following example:
try {
if (x) {
a();
return; // 1
}
b(); // 2
} catch (Exception e) {
c(); // 3
} finally {
d(); // 4
}
There are 4
distinct points of exit out of these "try/catch/finally"
blocks - three without exception, and one with Throwable if it is thrown
prior to reaching first three points of exit.
"finally" block must be executed just before these points, so there must be 4
copies of its bytecode instructions.
One of them handles Throwable ("catch-any") and must cover all instructions
of "try/catch" blocks. But must not cover instructions of other duplicates,
because instructions of "finally" block also can cause Throwable to be
thrown.
Therefore there will be multiple
MethodNode.tryCatchBlocks
with
TryCatchBlockNode.type
null with same
TryCatchBlockNode.handler
for different non-intersecting bytecode
regions (
TryCatchBlockNode.start
,
TryCatchBlockNode.end
).
And each exit out of these regions, except one that handles Throwable, will
contain duplicate of "finally" block.
To determine exits out of these regions, they all must be processed together
at once, because execution can branch from one region to another (like it is
in given example due to "if" statement).