* Fixed a bug where a user can break Netty when he or she calls setSuccess() on AbstractChannel.closeFuture

* UnfailingChannelFuture is not used anymore - deleting
This commit is contained in:
Trustin Lee 2010-01-09 05:40:40 +00:00
parent e2086cb754
commit c8fc3a1135
2 changed files with 25 additions and 48 deletions

View File

@ -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();
}
}
}

View File

@ -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);
}
}