From 49bac1aa73e0c83f1d6526c95954ed3b8bcb7485 Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Mon, 18 Aug 2008 11:24:04 +0000 Subject: [PATCH] Fixed an issue: NETTY-15 (NullPointerException in SslHandler if handshake() method is not called explicitly.) * Modified SslHandler.setHandshakeSuccess/Failure(..) to create a new handshakeFuture if not created yet. --- .../jboss/netty/handler/ssl/SslHandler.java | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/jboss/netty/handler/ssl/SslHandler.java b/src/main/java/org/jboss/netty/handler/ssl/SslHandler.java index 5a9a1d17be..8d9fdfbe3b 100644 --- a/src/main/java/org/jboss/netty/handler/ssl/SslHandler.java +++ b/src/main/java/org/jboss/netty/handler/ssl/SslHandler.java @@ -328,7 +328,7 @@ public class SslHandler extends FrameDecoder implements ChannelDownstreamHandler runDelegatedTasks(); break; case FINISHED: - setHandshakeSuccess(); + setHandshakeSuccess(channel); default: if (result.getStatus() == Status.CLOSED) { success = false; @@ -341,7 +341,7 @@ public class SslHandler extends FrameDecoder implements ChannelDownstreamHandler } catch (SSLException e) { success = false; if (handshaking) { - setHandshakeFailure(e); + setHandshakeFailure(channel, e); } throw e; } finally { @@ -413,7 +413,7 @@ public class SslHandler extends FrameDecoder implements ChannelDownstreamHandler switch (result.getHandshakeStatus()) { case FINISHED: - setHandshakeSuccess(); + setHandshakeSuccess(channel); break; case NEED_TASK: runDelegatedTasks(); @@ -426,7 +426,7 @@ public class SslHandler extends FrameDecoder implements ChannelDownstreamHandler } } catch (SSLException e) { if (handshaking) { - setHandshakeFailure(e); + setHandshakeFailure(channel, e); } throw e; } finally { @@ -463,7 +463,7 @@ public class SslHandler extends FrameDecoder implements ChannelDownstreamHandler runDelegatedTasks(); break; case FINISHED: - setHandshakeSuccess(); + setHandshakeSuccess(channel); case NOT_HANDSHAKING: wrap(ctx, channel); break loop; @@ -483,7 +483,7 @@ public class SslHandler extends FrameDecoder implements ChannelDownstreamHandler } } catch (SSLException e) { if (handshaking) { - setHandshakeFailure(e); + setHandshakeFailure(channel, e); } throw e; } finally { @@ -498,18 +498,26 @@ public class SslHandler extends FrameDecoder implements ChannelDownstreamHandler } } - private void setHandshakeSuccess() { + private void setHandshakeSuccess(Channel channel) { synchronized (handshakeLock) { handshaking = false; handshaken = true; + + if (handshakeFuture != null) { + handshakeFuture = future(channel); + } } handshakeFuture.setSuccess(); } - private void setHandshakeFailure(SSLException cause) { + private void setHandshakeFailure(Channel channel, SSLException cause) { synchronized (handshakeLock) { handshaking = false; handshaken = false; + + if (handshakeFuture != null) { + handshakeFuture = future(channel); + } } handshakeFuture.setFailure(cause); }