From c8fc3a113597b3982f745b8128c1dc6322cc95de Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Sat, 9 Jan 2010 05:40:40 +0000 Subject: [PATCH] * Fixed a bug where a user can break Netty when he or she calls setSuccess() on AbstractChannel.closeFuture * UnfailingChannelFuture is not used anymore - deleting --- .../jboss/netty/channel/AbstractChannel.java | 27 ++++++++++- .../netty/channel/UnfailingChannelFuture.java | 46 ------------------- 2 files changed, 25 insertions(+), 48 deletions(-) delete mode 100644 src/main/java/org/jboss/netty/channel/UnfailingChannelFuture.java diff --git a/src/main/java/org/jboss/netty/channel/AbstractChannel.java b/src/main/java/org/jboss/netty/channel/AbstractChannel.java index 7ec01227a6..7d33318455 100644 --- a/src/main/java/org/jboss/netty/channel/AbstractChannel.java +++ b/src/main/java/org/jboss/netty/channel/AbstractChannel.java @@ -64,7 +64,7 @@ public abstract class AbstractChannel implements Channel { private final ChannelFactory factory; private final ChannelPipeline pipeline; private final ChannelFuture succeededFuture = new SucceededChannelFuture(this); - private final ChannelFuture closeFuture = new UnfailingChannelFuture(this, false); + private final ChannelCloseFuture closeFuture = new ChannelCloseFuture(); private volatile int interestOps = OP_READ; /** Cache for the string representation of this channel */ @@ -163,7 +163,7 @@ public abstract class AbstractChannel implements Channel { * closed yet */ protected boolean setClosed() { - return closeFuture.setSuccess(); + return closeFuture.setClosed(); } public ChannelFuture bind(SocketAddress localAddress) { @@ -309,4 +309,27 @@ public abstract class AbstractChannel implements Channel { } return answer; } + + private final class ChannelCloseFuture extends DefaultChannelFuture { + + public ChannelCloseFuture() { + super(AbstractChannel.this, false); + } + + @Override + public boolean setSuccess() { + // User is not supposed to call this method - ignore silently. + return false; + } + + @Override + public boolean setFailure(Throwable cause) { + // User is not supposed to call this method - ignore silently. + return false; + } + + boolean setClosed() { + return super.setSuccess(); + } + } } diff --git a/src/main/java/org/jboss/netty/channel/UnfailingChannelFuture.java b/src/main/java/org/jboss/netty/channel/UnfailingChannelFuture.java deleted file mode 100644 index 72dd6fa021..0000000000 --- a/src/main/java/org/jboss/netty/channel/UnfailingChannelFuture.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2009 Red Hat, Inc. - * - * Red Hat licenses this file to you under the Apache License, version 2.0 - * (the "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package org.jboss.netty.channel; - -/** - * The {@link ChannelFuture} which can not fail at all. Any attempt to mark - * this future as failure, by calling {@link #setFailure(Throwable)} will raise - * an {@link IllegalStateException}. - * - * @author The Netty Project (netty-dev@lists.jboss.org) - * @author Trustin Lee (trustin@gmail.com) - * - * @version $Rev$, $Date$ - */ -public class UnfailingChannelFuture extends DefaultChannelFuture { - - /** - * Creates a new instance. - * - * @param channel - * the {@link Channel} associated with this future - * @param cancellable - * {@code true} if and only if this future can be canceled - */ - public UnfailingChannelFuture(Channel channel, boolean cancellable) { - super(channel, cancellable); - } - - @Override - public boolean setFailure(Throwable cause) { - throw new IllegalStateException("Can not fail", cause); - } -}