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

ErrorHandler fails to render exception if Exception.getMessage() returns null. #59

Closed
bckfnn opened this issue Mar 2, 2015 · 1 comment

Comments

@bckfnn
Copy link

bckfnn commented Mar 2, 2015

In snapshot vertx-apex-3.0.0-20150302.172251-43, an ErrorHandler with displayExceptionDetails=true will itself throw an exception when the orginal exception have a null getMessage().

SEVERE: Unexpected exception in route
java.lang.NullPointerException: reasonPhrase
    at io.netty.handler.codec.http.HttpResponseStatus.<init>(HttpResponseStatus.java:478)
    at io.netty.handler.codec.http.HttpResponseStatus.<init>(HttpResponseStatus.java:468)
    at io.vertx.core.http.impl.HttpServerResponseImpl.setStatusMessage(HttpServerResponseImpl.java:122)
    at io.vertx.ext.apex.handler.impl.ErrorHandlerImpl.handle(ErrorHandlerImpl.java:77)
    at io.vertx.ext.apex.handler.impl.ErrorHandlerImpl.handle(ErrorHandlerImpl.java:35)
    at io.vertx.ext.apex.impl.RouteImpl.handleFailure(RouteImpl.java:203)
    at io.vertx.ext.apex.impl.RoutingContextImplBase.iterateNext(RoutingContextImplBase.java:65)
    at io.vertx.ext.apex.impl.RoutingContextImpl.next(RoutingContextImpl.java:98)
    at io.vertx.ext.apex.impl.RoutingContextImpl.doFail(RoutingContextImpl.java:290)
    at io.vertx.ext.apex.impl.RoutingContextImpl.fail(RoutingContextImpl.java:124)
    at io.vertx.ext.apex.impl.RoutingContextImplBase.iterateNext(RoutingContextImplBase.java:73)
    at io.vertx.ext.apex.impl.RoutingContextImpl.next(RoutingContextImpl.java:98)
    at io.vertx.ext.apex.impl.RouterImpl.accept(RouterImpl.java:61)
    at dk.innovasion.support.ApexTest$$Lambda$8/105099923.handle(Unknown Source)
    at io.vertx.core.http.impl.ServerConnection.handleRequest(ServerConnection.java:262)
    at io.vertx.core.http.impl.ServerConnection.processMessage(ServerConnection.java:364)
    at io.vertx.core.http.impl.ServerConnection.handleMessage(ServerConnection.java:129)
    at io.vertx.core.http.impl.HttpServerImpl$ServerHandler.doMessageReceived(HttpServerImpl.java:522)
    at io.vertx.core.http.impl.HttpServerImpl$ServerHandler.doMessageReceived(HttpServerImpl.java:453)
    at io.vertx.core.http.impl.VertxHttpHandler.lambda$channelRead$5(VertxHttpHandler.java:71)
    at io.vertx.core.http.impl.VertxHttpHandler$$Lambda$14/1054055130.run(Unknown Source)
    at io.vertx.core.impl.ContextImpl.lambda$wrapTask$3(ContextImpl.java:258)
    at io.vertx.core.impl.ContextImpl$$Lambda$4/1237598030.run(Unknown Source)
    at io.vertx.core.impl.ContextImpl.executeSync(ContextImpl.java:165)
    at io.vertx.core.http.impl.VertxHttpHandler.channelRead(VertxHttpHandler.java:71)
    at io.vertx.core.net.impl.VertxHandler.channelRead(VertxHandler.java:131)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294)
    at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:182)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294)
    at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:846)
    at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:130)
    at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:511)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:468)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:382)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354)
    at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:116)
    at java.lang.Thread.run(Thread.java:744)

A reproducer:

package dk.innovasion.support;

import io.vertx.core.AbstractVerticle;
import io.vertx.core.Vertx;
import io.vertx.core.http.HttpServer;
import io.vertx.core.http.HttpServerOptions;
import io.vertx.ext.apex.Router;
import io.vertx.ext.apex.handler.ErrorHandler;

public class ApexTest extends AbstractVerticle {
    @Override
    public void start() throws Exception {
        Router router = Router.router(vertx);

        router.route().path("/ok").handler(ctx -> {
            throw new NullPointerException("message"); 
        });

        router.route().path("/fail").handler(ctx -> {
            throw new NullPointerException(); 
        });
        router.route().failureHandler(ErrorHandler.create(true));

        HttpServerOptions options = new HttpServerOptions();
        options.setPort(8080);

        HttpServer server = vertx.createHttpServer(options);
        server.requestHandler(router::accept).listen();
    }

    public static void main(String[] args) {
        Vertx vertx = Vertx.vertx();

        vertx.deployVerticle(ApexTest.class.getName(), res -> {
            System.out.println(res.succeeded() + " " + res.cause());
        });
    }
}

Hitting localhost:8080/ok shows a nice stacktrace
Hitting localhost:8080/fail shows "Internal Server Error" and the cause exception stacktrace is lost.

@bckfnn bckfnn changed the title ErrorHandler fails to render exception is Exception.getMessage() returns null. ErrorHandler fails to render exception if Exception.getMessage() returns null. Mar 17, 2015
@purplefox
Copy link
Contributor

Should be fixed now.

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

No branches or pull requests

2 participants