jeudi 18 juin 2020

Java Proxy and Vaadin throws NullPointerException

I am attempting to register a ClickListener to a Button. I am using Vaadin 8. This listener should be implemented using Proxy.

final Button button = new Button("Hello");

final Class<?> clickListenerClass = Button.ClickListener.class;
final Object clickListenerInstance = Proxy.newProxyInstance(clickListenerClass.getClassLoader(),
    new Class[] {clickListenerClass}, (proxy, method, args) -> {
        System.out.println("TEST");

        return null;
    });

button.addClickListener((Button.ClickListener)clickListenerInstance);

Here is the stack trace (I have omitted my code. The exception occurs on the last line of the above snippet).

java.lang.NullPointerException: null
    at com.sun.proxy.$Proxy20.hashCode(Unknown Source)
    at com.vaadin.event.ListenerMethod.hashCode(ListenerMethod.java:571)
    at java.util.HashMap.hash(HashMap.java:339)
    at java.util.HashMap.put(HashMap.java:612)
    at java.util.HashSet.add(HashSet.java:220)
    at com.vaadin.event.EventRouter.addListener(EventRouter.java:64)
    at com.vaadin.server.AbstractClientConnector.addListener(AbstractClientConnector.java:842)
    at com.vaadin.ui.Button.addClickListener(Button.java:333)




Aucun commentaire:

Enregistrer un commentaire