* Fixed most Find Bugs warnings

* Added UnreplayableOperationException
This commit is contained in:
Trustin Lee 2009-02-13 10:21:28 +00:00
parent fb64aa94b5
commit db18337762
12 changed files with 157 additions and 106 deletions

View File

@ -267,8 +267,8 @@ public class ClientBootstrap extends Bootstrap {
if (localAddress != null) {
event.getChannel().bind(localAddress);
} else {
futureQueue.offer(event.getChannel().connect(remoteAddress));
finished = true;
finished = futureQueue.offer(event.getChannel().connect(remoteAddress));
assert finished;
}
}
@ -280,8 +280,8 @@ public class ClientBootstrap extends Bootstrap {
// Connect if not connected yet.
if (localAddress != null) {
futureQueue.offer(event.getChannel().connect(remoteAddress));
finished = true;
finished = futureQueue.offer(event.getChannel().connect(remoteAddress));
assert finished;
}
}
@ -294,8 +294,8 @@ public class ClientBootstrap extends Bootstrap {
Throwable cause = e.getCause();
if (!(cause instanceof NotYetConnectedException) && !finished) {
e.getChannel().close();
futureQueue.offer(failedFuture(e.getChannel(), cause));
finished = true;
finished = futureQueue.offer(failedFuture(e.getChannel(), cause));
assert finished;
}
}
}

View File

@ -300,7 +300,8 @@ public class ServerBootstrap extends Bootstrap {
// Apply parent options.
evt.getChannel().getConfig().setOptions(parentOptions);
futureQueue.offer(evt.getChannel().bind(localAddress));
boolean finished = futureQueue.offer(evt.getChannel().bind(localAddress));
assert finished;
ctx.sendUpstream(evt);
}

View File

@ -27,6 +27,7 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.ReadOnlyBufferException;
import java.nio.channels.GatheringByteChannel;
import java.nio.channels.ScatteringByteChannel;
@ -72,55 +73,49 @@ public class ReadOnlyChannelBuffer extends AbstractChannelBuffer implements Wrap
@Override
public void discardReadBytes() {
rejectModification();
throw new ReadOnlyBufferException();
}
public void setByte(int index, byte value) {
rejectModification();
throw new ReadOnlyBufferException();
}
public void setBytes(int index, ChannelBuffer src, int srcIndex, int length) {
rejectModification();
throw new ReadOnlyBufferException();
}
public void setBytes(int index, byte[] src, int srcIndex, int length) {
rejectModification();
throw new ReadOnlyBufferException();
}
public void setBytes(int index, ByteBuffer src) {
rejectModification();
throw new ReadOnlyBufferException();
}
public void setShort(int index, short value) {
rejectModification();
throw new ReadOnlyBufferException();
}
public void setMedium(int index, int value) {
rejectModification();
throw new ReadOnlyBufferException();
}
public void setInt(int index, int value) {
rejectModification();
throw new ReadOnlyBufferException();
}
public void setLong(int index, long value) {
rejectModification();
throw new ReadOnlyBufferException();
}
public int setBytes(int index, InputStream in, int length)
throws IOException {
rejectModification();
return 0;
throw new ReadOnlyBufferException();
}
public int setBytes(int index, ScatteringByteChannel in, int length)
throws IOException {
rejectModification();
return 0;
}
protected void rejectModification() {
throw new UnsupportedOperationException("read-only");
throw new ReadOnlyBufferException();
}
public int getBytes(int index, GatheringByteChannel out, int length)

View File

@ -240,7 +240,8 @@ class NioProviderMetadata {
try {
level = autodetectWithoutTimeout();
} finally {
resultQueue.offer(Integer.valueOf(level));
boolean finished = resultQueue.offer(Integer.valueOf(level));
assert finished;
}
}
}, "NIO constraint level detector");

View File

@ -106,7 +106,8 @@ public class FactorialClientHandler extends SimpleChannelHandler {
// Offer the answer after closing the connection.
e.getChannel().close().addListener(new ChannelFutureListener() {
public void operationComplete(ChannelFuture future) {
answer.offer((BigInteger) e.getMessage());
boolean offered = answer.offer((BigInteger) e.getMessage());
assert offered;
}
});
}

View File

@ -119,7 +119,8 @@ public class LocalTimeClientHandler extends SimpleChannelHandler {
@Override
public void messageReceived(
ChannelHandlerContext ctx, final MessageEvent e) {
answer.offer((LocalTimes) e.getMessage());
boolean offered = answer.offer((LocalTimes) e.getMessage());
assert offered;
}
@Override

View File

@ -92,9 +92,11 @@ public abstract class HttpMessageDecoder extends ReplayingDecoder<HttpMessageDec
} finally {
checkpoint();
}
return null;
}
case READ_INITIAL: {
readInitial(buffer);
return null;
}
case READ_HEADER: {
readHeaders(buffer);
@ -135,10 +137,10 @@ public abstract class HttpMessageDecoder extends ReplayingDecoder<HttpMessageDec
chunkSize = getChunkSize(line);
if (chunkSize == 0) {
checkpoint(State.READ_CHUNK_FOOTER);
return null;
} else {
checkpoint(State.READ_CHUNKED_CONTENT);
}
return null;
}
case READ_CHUNKED_CONTENT: {
if (mergeChunks) {

View File

@ -56,7 +56,7 @@ class ReplayingDecoderBuffer implements ChannelBuffer {
}
public void clear() {
reject();
throw new UnreplayableOperationException();
}
@Override
@ -65,13 +65,11 @@ class ReplayingDecoderBuffer implements ChannelBuffer {
}
public int compareTo(ChannelBuffer buffer) {
reject();
return 0;
throw new UnreplayableOperationException();
}
public ChannelBuffer copy() {
reject();
return null;
throw new UnreplayableOperationException();
}
public ChannelBuffer copy(int index, int length) {
@ -80,12 +78,11 @@ class ReplayingDecoderBuffer implements ChannelBuffer {
}
public void discardReadBytes() {
reject();
throw new UnreplayableOperationException();
}
public ChannelBuffer duplicate() {
reject();
return null;
throw new UnreplayableOperationException();
}
public byte getByte(int index) {
@ -109,7 +106,7 @@ class ReplayingDecoderBuffer implements ChannelBuffer {
}
public void getBytes(int index, ByteBuffer dst) {
reject();
throw new UnreplayableOperationException();
}
public void getBytes(int index, ChannelBuffer dst, int dstIndex, int length) {
@ -118,22 +115,21 @@ class ReplayingDecoderBuffer implements ChannelBuffer {
}
public void getBytes(int index, ChannelBuffer dst, int length) {
reject();
throw new UnreplayableOperationException();
}
public void getBytes(int index, ChannelBuffer dst) {
reject();
throw new UnreplayableOperationException();
}
public int getBytes(int index, GatheringByteChannel out, int length)
throws IOException {
reject();
return -1;
throw new UnreplayableOperationException();
}
public void getBytes(int index, OutputStream out, int length)
throws IOException {
reject();
throw new UnreplayableOperationException();
}
public int getInt(int index) {
@ -173,8 +169,7 @@ class ReplayingDecoderBuffer implements ChannelBuffer {
@Override
public int hashCode() {
reject();
return 0;
throw new UnreplayableOperationException();
}
public int indexOf(int fromIndex, int toIndex, byte value) {
@ -199,7 +194,7 @@ class ReplayingDecoderBuffer implements ChannelBuffer {
}
public void markWriterIndex() {
reject();
throw new UnreplayableOperationException();
}
public ChannelBufferFactory factory() {
@ -239,7 +234,7 @@ class ReplayingDecoderBuffer implements ChannelBuffer {
}
public void readBytes(ByteBuffer dst) {
reject();
throw new UnreplayableOperationException();
}
public void readBytes(ChannelBuffer dst, int dstIndex, int length) {
@ -248,11 +243,11 @@ class ReplayingDecoderBuffer implements ChannelBuffer {
}
public void readBytes(ChannelBuffer dst, int length) {
reject();
throw new UnreplayableOperationException();
}
public void readBytes(ChannelBuffer dst) {
reject();
throw new UnreplayableOperationException();
}
public ChannelBuffer readBytes(ChannelBufferIndexFinder endIndexFinder) {
@ -265,8 +260,7 @@ class ReplayingDecoderBuffer implements ChannelBuffer {
public int readBytes(GatheringByteChannel out, int length)
throws IOException {
reject();
return -1;
throw new UnreplayableOperationException();
}
public ChannelBuffer readBytes(int length) {
@ -289,7 +283,7 @@ class ReplayingDecoderBuffer implements ChannelBuffer {
}
public void readBytes(OutputStream out, int length) throws IOException {
reject();
throw new UnreplayableOperationException();
}
public int readerIndex() {
@ -340,71 +334,69 @@ class ReplayingDecoderBuffer implements ChannelBuffer {
}
public void resetWriterIndex() {
reject();
throw new UnreplayableOperationException();
}
public void setByte(int index, byte value) {
reject();
throw new UnreplayableOperationException();
}
public void setBytes(int index, byte[] src, int srcIndex, int length) {
reject();
throw new UnreplayableOperationException();
}
public void setBytes(int index, byte[] src) {
reject();
throw new UnreplayableOperationException();
}
public void setBytes(int index, ByteBuffer src) {
reject();
throw new UnreplayableOperationException();
}
public void setBytes(int index, ChannelBuffer src, int srcIndex, int length) {
reject();
throw new UnreplayableOperationException();
}
public void setBytes(int index, ChannelBuffer src, int length) {
reject();
throw new UnreplayableOperationException();
}
public void setBytes(int index, ChannelBuffer src) {
reject();
throw new UnreplayableOperationException();
}
public int setBytes(int index, InputStream in, int length)
throws IOException {
reject();
return -1;
throw new UnreplayableOperationException();
}
public void setZero(int index, int length) {
reject();
throw new UnreplayableOperationException();
}
public int setBytes(int index, ScatteringByteChannel in, int length)
throws IOException {
reject();
return -1;
throw new UnreplayableOperationException();
}
public void setIndex(int readerIndex, int writerIndex) {
reject();
throw new UnreplayableOperationException();
}
public void setInt(int index, int value) {
reject();
throw new UnreplayableOperationException();
}
public void setLong(int index, long value) {
reject();
throw new UnreplayableOperationException();
}
public void setMedium(int index, int value) {
reject();
throw new UnreplayableOperationException();
}
public void setShort(int index, short value) {
reject();
throw new UnreplayableOperationException();
}
public int skipBytes(ChannelBufferIndexFinder firstIndexFinder) {
@ -423,8 +415,7 @@ class ReplayingDecoderBuffer implements ChannelBuffer {
}
public ChannelBuffer slice() {
reject();
return null;
throw new UnreplayableOperationException();
}
public ChannelBuffer slice(int index, int length) {
@ -433,8 +424,7 @@ class ReplayingDecoderBuffer implements ChannelBuffer {
}
public ByteBuffer toByteBuffer() {
reject();
return null;
throw new UnreplayableOperationException();
}
public ByteBuffer toByteBuffer(int index, int length) {
@ -442,8 +432,7 @@ class ReplayingDecoderBuffer implements ChannelBuffer {
}
public ByteBuffer[] toByteBuffers() {
reject();
return null;
throw new UnreplayableOperationException();
}
public ByteBuffer[] toByteBuffers(int index, int length) {
@ -464,14 +453,12 @@ class ReplayingDecoderBuffer implements ChannelBuffer {
}
public String toString(String charsetName) {
reject();
return null;
throw new UnreplayableOperationException();
}
public String toString(
String charsetName, ChannelBufferIndexFinder terminatorFinder) {
reject();
return null;
throw new UnreplayableOperationException();
}
@Override
@ -488,57 +475,56 @@ class ReplayingDecoderBuffer implements ChannelBuffer {
}
public void writeByte(byte value) {
reject();
throw new UnreplayableOperationException();
}
public void writeBytes(byte[] src, int srcIndex, int length) {
reject();
throw new UnreplayableOperationException();
}
public void writeBytes(byte[] src) {
reject();
throw new UnreplayableOperationException();
}
public void writeBytes(ByteBuffer src) {
reject();
throw new UnreplayableOperationException();
}
public void writeBytes(ChannelBuffer src, int srcIndex, int length) {
reject();
throw new UnreplayableOperationException();
}
public void writeBytes(ChannelBuffer src, int length) {
reject();
throw new UnreplayableOperationException();
}
public void writeBytes(ChannelBuffer src) {
reject();
throw new UnreplayableOperationException();
}
public void writeBytes(InputStream in, int length) throws IOException {
reject();
throw new UnreplayableOperationException();
}
public int writeBytes(ScatteringByteChannel in, int length)
throws IOException {
reject();
return -1;
throw new UnreplayableOperationException();
}
public void writeInt(int value) {
reject();
throw new UnreplayableOperationException();
}
public void writeLong(long value) {
reject();
throw new UnreplayableOperationException();
}
public void writeMedium(int value) {
reject();
throw new UnreplayableOperationException();
}
public void writeZero(int length) {
reject();
throw new UnreplayableOperationException();
}
public int writerIndex() {
@ -546,11 +532,11 @@ class ReplayingDecoderBuffer implements ChannelBuffer {
}
public void writerIndex(int writerIndex) {
reject();
throw new UnreplayableOperationException();
}
public void writeShort(short value) {
reject();
throw new UnreplayableOperationException();
}
private void checkIndex(int index) {
@ -570,9 +556,4 @@ class ReplayingDecoderBuffer implements ChannelBuffer {
throw REPLAY;
}
}
private void reject() {
throw new UnsupportedOperationException(
"Unsupported in " + ReplayingDecoder.class.getSimpleName());
}
}

View File

@ -0,0 +1,62 @@
/*
* JBoss, Home of Professional Open Source
*
* Copyright 2009, Red Hat Middleware LLC, and individual contributors
* by the @author tags. See the COPYRIGHT.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.netty.handler.codec.replay;
/**
* @author The Netty Project (netty-dev@lists.jboss.org)
* @author Trustin Lee (tlee@redhat.com)
* @version $Rev$, $Date$
*/
public class UnreplayableOperationException extends
UnsupportedOperationException {
private static final long serialVersionUID = 8577363912862364021L;
/**
* Creates a new instance.
*/
public UnreplayableOperationException() {
super();
}
/**
* Creates a new instance.
*/
public UnreplayableOperationException(String message) {
super(message);
}
/**
* Creates a new instance.
*/
public UnreplayableOperationException(Throwable cause) {
super(cause);
}
/**
* Creates a new instance.
*/
public UnreplayableOperationException(String message, Throwable cause) {
super(message, cause);
}
}

View File

@ -85,6 +85,7 @@ public class CompatibleObjectDecoder extends ReplayingDecoder<CompatibleObjectDe
case READ_HEADER:
oin = newObjectInputStream(bin);
checkpoint(CompatibleObjectDecoderState.READ_OBJECT);
return null;
case READ_OBJECT:
return oin.readObject();
default:

View File

@ -35,6 +35,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
import javax.net.ssl.SSLEngine;
import javax.net.ssl.SSLEngineResult;
import javax.net.ssl.SSLException;
import javax.net.ssl.SSLEngineResult.HandshakeStatus;
import javax.net.ssl.SSLEngineResult.Status;
import org.jboss.netty.buffer.ChannelBuffer;
@ -473,7 +474,8 @@ public class SslHandler extends FrameDecoder {
}
offered = true;
} else {
switch (result.getHandshakeStatus()) {
HandshakeStatus handshakeStatus = result.getHandshakeStatus();
switch (handshakeStatus) {
case NEED_WRAP:
if (outAppBuf.hasRemaining()) {
break;
@ -487,8 +489,10 @@ public class SslHandler extends FrameDecoder {
runDelegatedTasks();
break;
case FINISHED:
setHandshakeSuccess(channel);
case NOT_HANDSHAKING:
if (handshakeStatus == HandshakeStatus.FINISHED) {
setHandshakeSuccess(channel);
}
if (result.getStatus() == Status.CLOSED) {
success = false;
}
@ -589,6 +593,8 @@ public class SslHandler extends FrameDecoder {
switch (result.getHandshakeStatus()) {
case FINISHED:
setHandshakeSuccess(channel);
runDelegatedTasks();
break;
case NEED_TASK:
runDelegatedTasks();
break;

View File

@ -58,13 +58,13 @@ class ServletChannelHandler extends SimpleChannelHandler {
private final long reconnectTimeout;
boolean connected = false;
private volatile boolean connected = false;
AtomicBoolean invalidated = new AtomicBoolean(false);
private final AtomicBoolean invalidated = new AtomicBoolean(false);
private ServletOutputStream outputStream;
private volatile ServletOutputStream outputStream;
final boolean stream;
private final boolean stream;
private final HttpSession session;