diff --git a/asm/src/main/java/com/baeldung/examples/asm/instrumentation/Premain.java b/asm/src/main/java/com/baeldung/examples/asm/instrumentation/Premain.java index 105d7227d5..a3e69b6785 100644 --- a/asm/src/main/java/com/baeldung/examples/asm/instrumentation/Premain.java +++ b/asm/src/main/java/com/baeldung/examples/asm/instrumentation/Premain.java @@ -1,19 +1,32 @@ package com.baeldung.examples.asm.instrumentation; import com.baeldung.examples.asm.CustomClassWriter; - +import java.lang.instrument.ClassFileTransformer; +import java.lang.instrument.IllegalClassFormatException; import java.lang.instrument.Instrumentation; +import java.security.ProtectionDomain; +/** + * + * @author baeldung + */ public class Premain { public static void premain(String agentArgs, Instrumentation inst) { - inst.addTransformer((l, name, c, d, b) -> { + inst.addTransformer(new ClassFileTransformer() { - if (name.equals("java/lang/Integer")) { - CustomClassWriter cr = new CustomClassWriter(b); - return cr.addField(); + @Override + public byte[] transform(ClassLoader l, String name, Class c, + ProtectionDomain d, byte[] b) + throws IllegalClassFormatException { + + if (name.equals("java/lang/Integer")) { + CustomClassWriter cr = new CustomClassWriter(b); + return cr.addField(); + } + return b; } - return b; }); } + }