vaadin / flow

Vaadin Flow is a Java framework binding Vaadin web components to Java. This is part of Vaadin 10+.
Apache License 2.0
620 stars 167 forks source link

Flow needs to be in the restart class loader to work with Spring Boot's developer tools #3227

Closed tulioag closed 6 years ago

tulioag commented 6 years ago

When using flow with Spring Boot's developer tools, I get an IllegalArgumentException after I make a change and the application reloads. It seems that references to project's elements created in the initial restart classloader are kept in CustomElementRegistry.customElements. After the reload, the constructor tries to set fields with values from a different class loader, causing the exception.

Caused by: java.lang.IllegalArgumentException
    at com.vaadin.util.ReflectTools.setJavaFieldValue(ReflectTools.java:203) ~[flow-server-1.0.0.alpha13.jar:na]
    at com.vaadin.ui.polymertemplate.TemplateInitializer.injectTemplateElement(TemplateInitializer.java:422) ~[flow-server-1.0.0.alpha13.jar:na]
    at com.vaadin.ui.polymertemplate.TemplateInitializer.attachExistingElementById(TemplateInitializer.java:401) ~[flow-server-1.0.0.alpha13.jar:na]
    at com.vaadin.ui.polymertemplate.TemplateInitializer.injectClientSideElement(TemplateInitializer.java:360) ~[flow-server-1.0.0.alpha13.jar:na]
    at com.vaadin.ui.polymertemplate.TemplateInitializer.tryMapComponentOrElement(TemplateInitializer.java:314) ~[flow-server-1.0.0.alpha13.jar:na]
    at com.vaadin.ui.polymertemplate.TemplateInitializer.lambda$mapComponents$4(TemplateInitializer.java:284) ~[flow-server-1.0.0.alpha13.jar:na]
    at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184) ~[na:1.8.0_151]
    at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175) ~[na:1.8.0_151]
    at java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948) ~[na:1.8.0_151]
    at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481) ~[na:1.8.0_151]
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471) ~[na:1.8.0_151]
    at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151) ~[na:1.8.0_151]
    at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174) ~[na:1.8.0_151]
    at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[na:1.8.0_151]
    at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418) ~[na:1.8.0_151]
    at com.vaadin.ui.polymertemplate.TemplateInitializer.mapComponents(TemplateInitializer.java:284) ~[flow-server-1.0.0.alpha13.jar:na]
    at com.vaadin.ui.polymertemplate.TemplateInitializer.initChildElements(TemplateInitializer.java:142) ~[flow-server-1.0.0.alpha13.jar:na]
    at com.vaadin.ui.polymertemplate.PolymerTemplate.<init>(PolymerTemplate.java:62) ~[flow-server-1.0.0.alpha13.jar:na]
    at com.vaadin.ui.polymertemplate.PolymerTemplate.<init>(PolymerTemplate.java:72) ~[flow-server-1.0.0.alpha13.jar:na]
...
Caused by: java.lang.IllegalArgumentException
    at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167) ~[na:1.8.0_151]
    at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171) ~[na:1.8.0_151]
    at sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:81) ~[na:1.8.0_151]
    at java.lang.reflect.Field.set(Field.java:764) ~[na:1.8.0_151]
    at com.vaadin.util.ReflectTools.setJavaFieldValue(ReflectTools.java:198) ~[flow-server-1.0.0.alpha13.jar:na]
    ... 131 common frames omitted

Tested with: flow 1.0.0.alpha13

Legioth commented 6 years ago

One potential "fix" for this issue would be to completely remove the CustomElementRegistry feature as described in https://github.com/vaadin/flow/issues/2486.

denis-anisimov commented 6 years ago

Issue moved to vaadin/spring #274 via ZenHub