Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NPE with simple text response in RouterNanoHTTPD #543

Open
cmarchand opened this issue Jun 5, 2019 · 1 comment
Open

NPE with simple text response in RouterNanoHTTPD #543

cmarchand opened this issue Jun 5, 2019 · 1 comment

Comments

@cmarchand
Copy link

This is probably just a simple question, but I can't find any solution? Here me simple code, using 2.3.1 :

public class RestServer extends RouterNanoHTTPD {
    private final Notifiee notifiee;
    private RestServer(int port, Notifiee notifiee) {
        super(port);
        this.notifiee = notifiee;
        addRoute("/ping", PingHandler.class);
        addRoute("/stop", StopHandler.class);
    }
    public static class StopHandler extends DefaultHandler {
        public StopHandler() {
            super();
        }
        @Override
        public String getText() { 
            RestServer.getInstance().notifiee.askStop();
            return "Stop ask";
        }
        @Override
        public Response.IStatus getStatus() { 
            return Response.Status.OK;
        }
        @Override
        public String getMimeType() { 
            return MIME_PLAINTEXT;
        }
    }
}

When I call http://localhost:port/stop, I get this :

java.lang.NullPointerException
	at fi.iki.elonen.router.RouterNanoHTTPD$UriRouter.process(RouterNanoHTTPD.java:596)
	at fi.iki.elonen.router.RouterNanoHTTPD.serve(RouterNanoHTTPD.java:671)
	at fi.iki.elonen.NanoHTTPD$HTTPSession.execute(NanoHTTPD.java:945)
	at fi.iki.elonen.NanoHTTPD$ClientHandler.run(NanoHTTPD.java:192)
	at java.base/java.lang.Thread.run(Thread.java:834)

But notifiee.stop() is correctly call, I get response in browser. Just the NPE is thrown.
Any help will be much appreciated.

@sandrock
Copy link

Same here. Cant' find what that is about.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants