Skip to content

Commit 2202d52

Browse files
javier-godoypaodb
authored andcommitted
refactor: add check for missing asm dependency
1 parent 5086a28 commit 2202d52

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,15 @@ public class ViewInitializerImpl extends InstrumentationViewInitializer {
152152
}
153153
```
154154

155+
This feature requires a dependency with ASM (which is not provided out-of-the-box in Vaadin 14-23):
156+
```
157+
<dependency>
158+
<groupId>org.ow2.asm</groupId>
159+
<artifactId>asm</artifactId>
160+
<version>9.8</version>
161+
</dependency>
162+
```
163+
155164
## Direct Usage
156165

157166
The helper methods can also be used directly from the `JsonMigration` class:

src/main/java/com/flowingcode/vaadin/jsonmigration/ClassInstrumentationUtil.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,20 @@ final class ClassInstrumentationUtil {
6565

6666
private final Map<ClassLoader, InstrumentedClassLoader> classLoaderCache = new WeakHashMap<>();
6767

68+
private static final boolean IS_ASM_PRESENT;
69+
70+
static {
71+
boolean isPresent;
72+
try {
73+
Class.forName("org.objectweb.asm.ClassWriter", false,
74+
ClassInstrumentationUtil.class.getClassLoader());
75+
isPresent = true;
76+
} catch (ClassNotFoundException e) {
77+
isPresent = false;
78+
}
79+
IS_ASM_PRESENT = isPresent;
80+
}
81+
6882
ClassInstrumentationUtil(int version) {
6983
this.version = version;
7084
}
@@ -123,6 +137,10 @@ public <T extends Component> Class<? extends T> instrumentClass(Class<T> parent)
123137
return parent;
124138
}
125139

140+
if (!IS_ASM_PRESENT) {
141+
throw new IllegalStateException("Missing optional dependency org.ow2.asm:asm:9.8");
142+
}
143+
126144
// Check for accessible no-arg constructor
127145
try {
128146
Constructor<?> defaultConstructor = parent.getDeclaredConstructor();

0 commit comments

Comments
 (0)