Method defineClassMethod = ClassLoader.class.getDeclaredMethod("defineClass", String.class, byte[].class,
int.class, int.class);
defineClassMethod.setAccessible(true);
ByteArray ba = StreamUtil.readBytes(
LoggerHacker.class.getClassLoader().getResource(className.replace('.', '/') + ".class")
.openStream(), true);
try {
defineClassMethod.invoke(loader, className, ba.getRawBytes(), ba.getOffset(), ba.getLength());
} catch (InvocationTargetException e) {
throw e.getTargetException();
}
} catch (Throwable e) {
slf4jLog.debug("Failed to define {}: {}", className, e.getMessage());