Hello.
Java 9 introduced the VarHandle infrastructure that allows atomic and plain access to fields and array elements. To initialize a VarHandle, one must perform the following "dance" every time:
class A {
int field;
static final VarHandle FIELD;
static {
try {
FIELD = MethodHandles.lookup().findVarHandle(A.class, "field", Integer.TYPE);
} catch (Throwable ex) {
throw new InternalError(ex);
}
}
}
When covering such classes, the problem is that the catch will never get executed because findVarHandle can't fail (if coded properly). Factoring out MethodHandles.lookup().findVarHandle into some common method doesn't work most of the time because of runtime access checks regarding the target class and field (usually would require to make everything public).
Is there a way to exclude such impossible paths from the coverage statistics or do I have to live with such uncoverable code paths (i.e., similar to some synchronized and finally blocks that can never fail)?