Artur- / spring-boot-loaded-vaadin

Test project for using Spring Boot + Spring Loaded + Vaadin
1 stars 2 forks source link

problems when using java 8 lambdas #1

Open darkwitch opened 8 years ago

darkwitch commented 8 years ago

Hi,

You're demo works correctly until I try using lambdas. If you change:

Button button = new Button("Click Me");
button.addClickListener(new Button.ClickListener() {
    @Override
    public void buttonClick(ClickEvent event) {
        layout.addComponent(new Label("Thank you for clicking"));
    }
});
layout.addComponent(button);

to java 8 lambda

Button button = new Button("Click Me");
button.addClickListener((Button.ClickListener) event -> layout.addComponent(new Label("Thank you for clicking")));
layout.addComponent(button);

Things start to go hairy, some changes work, some produce nasty exceptions.

For ex. extracting a method for the label caption like this:

[...]
    Button button = new Button("Click Me");
    button.addClickListener((Button.ClickListener) event -> layout.addComponent(new Label(getLabelContent())));
    layout.addComponent(button);
}

private String getLabelContent() {
    return "Thank you for clicking";
}

causes this stack trace. The application has to be restarted at this point.

java.util.concurrent.ExecutionException: java.lang.IllegalAccessError: no such method: org.vaadin.artur.MyUI.lambda$init$72dc4e82$1(VerticalLayout,ClickEvent)void/invokeSpecial
    at java.util.concurrent.FutureTask.report(FutureTask.java:122)
    at java.util.concurrent.FutureTask.get(FutureTask.java:192)
    at com.vaadin.server.VaadinSession$FutureAccess.get(VaadinSession.java:123)
    at com.vaadin.server.VaadinService.runPendingAccessTasks(VaadinService.java:1807)
    at com.vaadin.server.VaadinSession.unlock(VaadinSession.java:1019)
    at com.vaadin.server.VaadinService.ensureAccessQueuePurged(VaadinService.java:1768)
    at com.vaadin.server.VaadinService.accessSession(VaadinService.java:1734)
    at com.vaadin.server.VaadinSession.access(VaadinSession.java:1409)
    at com.vaadin.ui.UI.access(UI.java:1437)
    at org.vaadin.artur.AutoReloadUI.access(AutoReloadUI.java)
    at org.vaadin.artur.MyUI.access(MyUI.java)
    at org.vaadin.artur.AutoReloadUI.reloadEvent(AutoReloadUI.java:20)
    at org.vaadin.artur.MyUI.reloadEvent(MyUI.java)
    at org.springsource.loaded.TypeRegistry.fireReloadEvent(TypeRegistry.java:2021)
    at org.springsource.loaded.ReloadableType.loadNewVersion(ReloadableType.java:444)
    at org.springsource.loaded.TypeRegistry.loadNewVersion(TypeRegistry.java:1013)
    at org.springsource.loaded.agent.ReloadableFileChangeListener.fileChanged(ReloadableFileChangeListener.java:104)
    at org.springsource.loaded.agent.Watcher.determineChangesSince(FileSystemWatcher.java:251)
    at org.springsource.loaded.agent.Watcher.run(FileSystemWatcher.java:235)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalAccessError: no such method: org.vaadin.artur.MyUI.lambda$init$72dc4e82$1(VerticalLayout,ClickEvent)void/invokeSpecial
    at java.lang.invoke.MethodHandleNatives.linkMethodHandleConstant(MethodHandleNatives.java:448)
    at org.vaadin.artur.MyUI$$EPscXH44.init(MyUI.java:21)
    at org.vaadin.artur.MyUI$$DPscXH44.init(Unknown Source)
    at org.vaadin.artur.MyUI.init(MyUI.java)
    at org.vaadin.artur.AutoReloadUI.lambda$reloadEvent$0(AutoReloadUI.java:21)
    at org.vaadin.artur.AutoReloadUI$$Lambda$9/1693577210.run(Unknown Source)
    at com.vaadin.ui.UI.accessSynchronously(UI.java:1374)
    at org.vaadin.artur.AutoReloadUI.accessSynchronously(AutoReloadUI.java)
    at org.vaadin.artur.MyUI.accessSynchronously(MyUI.java)
    at com.vaadin.ui.UI$3.run(UI.java:1440)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at com.vaadin.server.VaadinService.runPendingAccessTasks(VaadinService.java:1804)
    ... 16 common frames omitted
Caused by: java.lang.IncompatibleClassChangeError: Expecting non-static method org.vaadin.artur.MyUI.lambda$init$72dc4e82$1(Lcom/vaadin/ui/VerticalLayout;Lcom/vaadin/ui/Button$ClickEvent;)V
    at java.lang.invoke.MethodHandleNatives.resolve(Native Method)
    at java.lang.invoke.MemberName$Factory.resolve(MemberName.java:965)
    at java.lang.invoke.MemberName$Factory.resolveOrFail(MemberName.java:990)
    at java.lang.invoke.MethodHandles$Lookup.resolveOrFail(MethodHandles.java:1387)
    at java.lang.invoke.MethodHandles$Lookup.linkMethodHandleConstant(MethodHandles.java:1739)
    at java.lang.invoke.MethodHandleNatives.linkMethodHandleConstant(MethodHandleNatives.java:442)
    ... 28 common frames omitted

Any clue how to get around this ?

Artur- commented 8 years ago

It is a problem in Spring loaded, see https://github.com/spring-projects/spring-loaded/issues/141