I cannot load a class after byte code modification with ASM library.
Here it is identity transformer and I expect to get modified array with the same size as bytes o
Those bytes correspond to 0xcafeba
which matches the Java class file magic number, 0xcafebabe
.
The problem here is that new ClassWriter(reader, 0)
does not do what you presumably believe it does; see the API documentation:
classReader
- the ClassReader used to read the original class. It will be used to copy the entire constant pool from the original class and also to copy other fragments of original bytecode where applicable.
We still need to actually have the writer visit the reader via ClassReader.accept, as follows:
reader.accept(writer, 0);
As a side note, you don't need IOUtils.toByteArary
as ClassReader
has a constructor taking InputStream.