diff --git a/byte-buddy-dep/src/main/java/net/bytebuddy/utility/JavaModule.java b/byte-buddy-dep/src/main/java/net/bytebuddy/utility/JavaModule.java index 5bb240560a0..1e3b3982598 100644 --- a/byte-buddy-dep/src/main/java/net/bytebuddy/utility/JavaModule.java +++ b/byte-buddy-dep/src/main/java/net/bytebuddy/utility/JavaModule.java @@ -156,7 +156,12 @@ public ClassLoader getClassLoader() { } catch (IllegalAccessException exception) { throw new IllegalStateException("Cannot access class loader for " + module, exception); } catch (InvocationTargetException exception) { - throw new IllegalStateException("Cannot read class loader for " + module, exception.getTargetException()); + Throwable cause = exception.getTargetException(); + if (cause instanceof RuntimeException) { + throw (RuntimeException) cause; + } else { + throw new IllegalStateException("Cannot read class loader for " + module, cause); + } } }