diff --git a/README.md b/README.md index d93dce6..ba4f1c1 100644 --- a/README.md +++ b/README.md @@ -152,6 +152,15 @@ public class ViewInitializerImpl extends InstrumentationViewInitializer { } ``` +This feature requires a dependency with ASM (which is not provided out-of-the-box in Vaadin 14-23): +``` + + org.ow2.asm + asm + 9.8 + +``` + ## Direct Usage The helper methods can also be used directly from the `JsonMigration` class: diff --git a/src/main/java/com/flowingcode/vaadin/jsonmigration/ClassInstrumentationUtil.java b/src/main/java/com/flowingcode/vaadin/jsonmigration/ClassInstrumentationUtil.java index 7512ddd..891e92b 100644 --- a/src/main/java/com/flowingcode/vaadin/jsonmigration/ClassInstrumentationUtil.java +++ b/src/main/java/com/flowingcode/vaadin/jsonmigration/ClassInstrumentationUtil.java @@ -65,6 +65,20 @@ final class ClassInstrumentationUtil { private final Map classLoaderCache = new WeakHashMap<>(); + private static final boolean IS_ASM_PRESENT; + + static { + boolean isPresent; + try { + Class.forName("org.objectweb.asm.ClassWriter", false, + ClassInstrumentationUtil.class.getClassLoader()); + isPresent = true; + } catch (ClassNotFoundException e) { + isPresent = false; + } + IS_ASM_PRESENT = isPresent; + } + ClassInstrumentationUtil(int version) { this.version = version; } @@ -123,6 +137,10 @@ public Class instrumentClass(Class parent) return parent; } + if (!IS_ASM_PRESENT) { + throw new IllegalStateException("Missing optional dependency org.ow2.asm:asm:9.8"); + } + // Check for accessible no-arg constructor try { Constructor defaultConstructor = parent.getDeclaredConstructor();