Thomas Broyer
07/15/2025, 3:27 PMgetMessage() lazily using a helper class (from that same third-party lib).
The problem is that, if I don't do anything special, Gradle will somehow "copy" the exception outside of the classLoaderIsolation or back to the Gradle Daemon process, but won't "copy" that helper class, so when Gradle wants to print the error message to the console and calls the exception's getMessage() method, that one will throw a ClassNotFoundException that will shadow the actual error.
How would you recommend handling this?Thomas Broyer
07/15/2025, 3:30 PMthrow new MyException(e.getMessage(), e.getCause()) ; possibly just using a RuntimeException, maybe prefixing), but there could be a similar issue in an exception in the stacktrace.
I could also look just log the error and throw an exception without any relation to the possibly-problematic one.
logger.error("…", e);
throw new RuntimeException("…"); // note: no cause here
Anything else? What would you recommend?tony
07/15/2025, 3:36 PMMartin
07/15/2025, 11:34 PMMartin
07/15/2025, 11:36 PMMartin
07/15/2025, 11:38 PMThomas Broyer
07/16/2025, 7:15 AMnew RuntimeException(e) is enough to make it work: when printing the stacktrace, the JVM is smart enough to run the getMessage() in the appropriate classloader so the helper class can be loaded without error 🤯 (and the runtime exception will have its message eagerly derived from the wrapped exception's toString, so the information is there too when stacktraces aren't printed)Martin
07/16/2025, 7:58 AMThomas Broyer
07/16/2025, 8:14 AMtry {
…
} catch (ProblematicException e) {
RuntimeException re = new RuntimeException(e.toString(), e.getCause());
re.setStackTrace(e.getStackTrace());
throw re;
}
Original exception class will be in the message (through toString), and stacktrace will be the same.Thomas Broyer
07/16/2025, 7:31 PM