GRADLE-1511/GRADLE-1996 - Handle exceptions that provide writeReplace() and/or readResolve() implementations.