eclipse-ee4j / tyrus

Tyrus
Other
113 stars 36 forks source link

NPE in AnnotatedEndpoint with version 2.0.0 when no ServerEndpoint is configured #724

Open apupier opened 3 years ago

apupier commented 3 years ago

I tried to migrate from previous version to 2.0.0, I replaced all javax.websocket to jakarta.websocket and I'm hitting this NPE:

[java.lang.NullPointerException
    at org.glassfish.tyrus.core.AnnotatedEndpoint.<init>(AnnotatedEndpoint.java:166)
    at org.glassfish.tyrus.core.AnnotatedEndpoint.fromClass(AnnotatedEndpoint.java:117)
    at org.glassfish.tyrus.core.TyrusWebSocketEngine.register(TyrusWebSocketEngine.java:647)
    at org.glassfish.tyrus.container.grizzly.server.GrizzlyServerContainer$1.register(GrizzlyServerContainer.java:136)
    at org.glassfish.tyrus.server.TyrusServerContainer.start(TyrusServerContainer.java:116)
    at org.glassfish.tyrus.container.grizzly.server.GrizzlyServerContainer$1.start(GrizzlyServerContainer.java:200)
    at org.glassfish.tyrus.server.Server.start(Server.java:205)
    at com.github.cameltooling.lsp.internal.websocket.WebSocketRunner.runWebSocketServer(WebSocketRunner.java:43)
    at com.github.cameltooling.lsp.internal.Runner.main(Runner.java:63)
    at com.github.cameltooling.lsp.internal.RunnerWebSocketTest$2.run(RunnerWebSocketTest.java:128)
    at java.base/java.lang.Thread.run(Thread.java:834)](url)

Here is the branch that I'm using https://github.com/apupier/camel-language-server/tree/tyrus.version-2.0.0-bugreport

Here is my ServerApplicationConfig class:

package com.github.cameltooling.lsp.internal.websocket;

import java.util.Collections;
import java.util.Set;

import jakarta.websocket.Endpoint;
import jakarta.websocket.server.ServerApplicationConfig;
import jakarta.websocket.server.ServerEndpointConfig;

public class CamelLSPWebSocketServerConfigProvider implements ServerApplicationConfig {

    private static final String WEBSOCKET_CAMEL_SERVER_PATH = "/camel-language-server";

    @Override
    public Set<ServerEndpointConfig> getEndpointConfigs(Set<Class<? extends Endpoint>> endpointClasses) {
        ServerEndpointConfig conf = ServerEndpointConfig.Builder.create(CamelLSPWebSocketEndpoint.class, WEBSOCKET_CAMEL_SERVER_PATH).build();
        return Collections.singleton(conf);
    }

    @Override
    public Set<Class<?>> getAnnotatedEndpointClasses(Set<Class<?>> scanned) {
        return scanned;
    }

}
apupier commented 3 years ago

the NPE is cause because the creation fo the configuration endpoitnConfig is failing. There is an error because my ServerEndpoint was still using javax.* (but cannot change directly as it is inherited from another library)

SO there is a problem of configuration but it woudl be nice to avoid the NPE so that the ErrorCollector can deliver what the issue is.