From fb0c568162fd6e03aa4855c0371e574d596f0cdf Mon Sep 17 00:00:00 2001
From: Javier Godoy <11554739+javier-godoy@users.noreply.github.com>
Date: Wed, 3 Dec 2025 11:53:07 -0300
Subject: [PATCH] refactor: add check for missing asm dependency
---
README.md | 9 +++++++++
.../ClassInstrumentationUtil.java | 18 ++++++++++++++++++
2 files changed, 27 insertions(+)
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 extends T> 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();