diff --git a/buffer/src/main/java/io/netty/buffer/CompositeByteBuf.java b/buffer/src/main/java/io/netty/buffer/CompositeByteBuf.java index 010652a916..636600b393 100644 --- a/buffer/src/main/java/io/netty/buffer/CompositeByteBuf.java +++ b/buffer/src/main/java/io/netty/buffer/CompositeByteBuf.java @@ -683,11 +683,11 @@ public class CompositeByteBuf extends AbstractByteBuf { // New readerIndex and writerIndex will become 0 and // (previous writerIndex - previous readerIndex) respectively. - final int localReaderIndex = this.readerIndex(); + final int localReaderIndex = readerIndex(); if (localReaderIndex == 0) { return; } - int localWriterIndex = this.writerIndex(); + int localWriterIndex = writerIndex(); final int bytesToMove = capacity() - localReaderIndex; List list = decompose(localReaderIndex, bytesToMove); @@ -712,14 +712,14 @@ public class CompositeByteBuf extends AbstractByteBuf { int localMarkedReaderIndex = localReaderIndex; try { resetReaderIndex(); - localMarkedReaderIndex = this.readerIndex(); + localMarkedReaderIndex = readerIndex(); } catch (IndexOutOfBoundsException e) { // ignore } int localMarkedWriterIndex = localWriterIndex; try { resetWriterIndex(); - localMarkedWriterIndex = this.writerIndex(); + localMarkedWriterIndex = writerIndex(); } catch (IndexOutOfBoundsException e) { // ignore } diff --git a/codec-http/pom.xml b/codec-http/pom.xml index 02bf6687bb..2d6e558a6b 100644 --- a/codec-http/pom.xml +++ b/codec-http/pom.xml @@ -34,11 +34,6 @@ netty-codec ${project.version} - - ${project.groupId} - netty-handler - ${project.version} - diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/HttpContentCompressor.java b/codec-http/src/main/java/io/netty/handler/codec/http/HttpContentCompressor.java index 425c47d018..2c8b917640 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/HttpContentCompressor.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/HttpContentCompressor.java @@ -137,11 +137,11 @@ public class HttpContentCompressor extends HttpContentEncoder { q = 0.0f; } } - if (encoding.indexOf("*") >= 0) { + if (encoding.contains("*")) { starQ = q; - } else if (encoding.indexOf("gzip") >= 0 && q > gzipQ) { + } else if (encoding.contains("gzip") && q > gzipQ) { gzipQ = q; - } else if (encoding.indexOf("deflate") >= 0 && q > deflateQ) { + } else if (encoding.contains("deflate") && q > deflateQ) { deflateQ = q; } } diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/HttpMessageDecoder.java b/codec-http/src/main/java/io/netty/handler/codec/http/HttpMessageDecoder.java index 7017e8d1d7..f12a3f2647 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/HttpMessageDecoder.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/HttpMessageDecoder.java @@ -269,7 +269,7 @@ public abstract class HttpMessageDecoder extends ReplayingDecoder actualReadableBytes()) { toRead = actualReadableBytes(); } - contentRead = contentRead + toRead; + contentRead += toRead; if (length < contentRead) { if (!message.isChunked()) { message.setChunked(true); diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/QueryStringDecoder.java b/codec-http/src/main/java/io/netty/handler/codec/http/QueryStringDecoder.java index e5e37307ac..526a97112e 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/QueryStringDecoder.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/QueryStringDecoder.java @@ -218,7 +218,7 @@ public class QueryStringDecoder { String name = null; int pos = 0; // Beginning of the unprocessed region int i; // End of the unprocessed region - char c = 0; // Current character + char c; // Current character for (i = 0; i < s.length(); i++) { c = s.charAt(i); if (c == '=' && name == null) { @@ -246,18 +246,12 @@ public class QueryStringDecoder { if (pos != i) { // Are there characters we haven't dealt with? if (name == null) { // Yes and we haven't seen any `='. - if (!addParam(params, decodeComponent(s.substring(pos, i), charset), "")) { - return; - } + addParam(params, decodeComponent(s.substring(pos, i), charset), ""); } else { // Yes and this must be the last value. - if (!addParam(params, name, decodeComponent(s.substring(pos, i), charset))) { - return; - } + addParam(params, name, decodeComponent(s.substring(pos, i), charset)); } } else if (name != null) { // Have we seen a name without value? - if (!addParam(params, name, "")) { - return; - } + addParam(params, name, ""); } } diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocket08FrameEncoder.java b/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocket08FrameEncoder.java index 98854ea824..f32d01a2d0 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocket08FrameEncoder.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocket08FrameEncoder.java @@ -103,27 +103,26 @@ public class WebSocket08FrameEncoder extends MessageToByteEncoder 125) { diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshaker.java b/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshaker.java index 6d5f71d1e3..c16f95f95c 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshaker.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshaker.java @@ -19,6 +19,7 @@ import io.netty.channel.Channel; import io.netty.channel.ChannelFuture; import io.netty.handler.codec.http.HttpRequest; +import java.util.Collections; import java.util.LinkedHashSet; import java.util.Set; @@ -79,9 +80,7 @@ public abstract class WebSocketServerHandshaker { */ public Set getSubprotocols() { Set ret = new LinkedHashSet(); - for (String p: subprotocols) { - ret.add(p); - } + Collections.addAll(ret, subprotocols); return ret; } diff --git a/codec-http/src/main/java/io/netty/handler/codec/rtsp/RtspHeaders.java b/codec-http/src/main/java/io/netty/handler/codec/rtsp/RtspHeaders.java index 0774324aa0..313342be13 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/rtsp/RtspHeaders.java +++ b/codec-http/src/main/java/io/netty/handler/codec/rtsp/RtspHeaders.java @@ -383,10 +383,8 @@ public final class RtspHeaders { */ public static final String URL = "url"; - protected Values() { - } + private Values() { } } - private RtspHeaders() { - } + private RtspHeaders() { } } diff --git a/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdyDataFrame.java b/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdyDataFrame.java index fbd5f4ea03..f352c5d126 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdyDataFrame.java +++ b/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdyDataFrame.java @@ -63,11 +63,13 @@ public class DefaultSpdyDataFrame implements SpdyDataFrame { } @Override + @Deprecated public boolean isCompressed() { return compressed; } @Override + @Deprecated public void setCompressed(boolean compressed) { this.compressed = compressed; } diff --git a/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdyHeadersFrame.java b/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdyHeadersFrame.java index fe39f742d3..527f96a477 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdyHeadersFrame.java +++ b/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdyHeadersFrame.java @@ -33,7 +33,6 @@ public class DefaultSpdyHeadersFrame extends DefaultSpdyHeaderBlock * @param streamID the Stream-ID of this frame */ public DefaultSpdyHeadersFrame(int streamID) { - super(); setStreamID(streamID); } diff --git a/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdySynReplyFrame.java b/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdySynReplyFrame.java index ced7dc6596..38068d6b91 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdySynReplyFrame.java +++ b/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdySynReplyFrame.java @@ -32,7 +32,6 @@ public class DefaultSpdySynReplyFrame extends DefaultSpdyHeaderBlock * @param streamID the Stream-ID of this frame */ public DefaultSpdySynReplyFrame(int streamID) { - super(); setStreamID(streamID); } diff --git a/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdySynStreamFrame.java b/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdySynStreamFrame.java index 5156f47e81..55fc1e64b2 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdySynStreamFrame.java +++ b/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdySynStreamFrame.java @@ -38,7 +38,6 @@ public class DefaultSpdySynStreamFrame extends DefaultSpdyHeaderBlock */ public DefaultSpdySynStreamFrame( int streamID, int associatedToStreamID, byte priority) { - super(); setStreamID(streamID); setAssociatedToStreamID(associatedToStreamID); setPriority(priority); diff --git a/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyCodecUtil.java b/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyCodecUtil.java index 514a808c42..18b57b8b30 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyCodecUtil.java +++ b/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyCodecUtil.java @@ -248,7 +248,7 @@ final class SpdyCodecUtil { ".1statusversionurl "; static final byte[] SPDY2_DICT; static { - byte[] SPDY2_DICT_ = null; + byte[] SPDY2_DICT_; try { SPDY2_DICT_ = SPDY2_DICT_S.getBytes("US-ASCII"); diff --git a/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyFrameDecoder.java b/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyFrameDecoder.java index 7271feafee..9df6a106b4 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyFrameDecoder.java +++ b/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyFrameDecoder.java @@ -15,13 +15,14 @@ */ package io.netty.handler.codec.spdy; -import static io.netty.handler.codec.spdy.SpdyCodecUtil.*; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.ByteToMessageDecoder; import io.netty.handler.codec.TooLongFrameException; +import static io.netty.handler.codec.spdy.SpdyCodecUtil.*; + /** * Decodes {@link ByteBuf}s into SPDY Data and Control Frames. */ @@ -49,7 +50,7 @@ public class SpdyFrameDecoder extends ByteToMessageDecoder { private int numHeaders; private ByteBuf decompressed; - private static enum State { + private enum State { READ_COMMON_HEADER, READ_CONTROL_FRAME, READ_SETTINGS_FRAME, diff --git a/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyFrameEncoder.java b/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyFrameEncoder.java index bca92ad7bf..9c671c11ec 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyFrameEncoder.java +++ b/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyFrameEncoder.java @@ -15,7 +15,6 @@ */ package io.netty.handler.codec.spdy; -import static io.netty.handler.codec.spdy.SpdyCodecUtil.*; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.channel.ChannelFuture; @@ -26,6 +25,8 @@ import io.netty.handler.codec.UnsupportedMessageTypeException; import java.util.Set; +import static io.netty.handler.codec.spdy.SpdyCodecUtil.*; + /** * Encodes a SPDY Data or Control Frame into a {@link ByteBuf}. */ @@ -48,7 +49,6 @@ public class SpdyFrameEncoder extends MessageToByteEncoder { * Creates a new instance with the specified parameters. */ public SpdyFrameEncoder(int version, int compressionLevel, int windowBits, int memLevel) { - super(); if (version < SpdyConstants.SPDY_MIN_VERSION || version > SpdyConstants.SPDY_MAX_VERSION) { throw new IllegalArgumentException( "unknown version: " + version); diff --git a/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyHeaders.java b/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyHeaders.java index a2bd40a323..336df21017 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyHeaders.java +++ b/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyHeaders.java @@ -62,9 +62,7 @@ public class SpdyHeaders { */ public static final String VERSION = ":version"; - private HttpNames() { - super(); - } + private HttpNames() { } } /** @@ -93,9 +91,7 @@ public class SpdyHeaders { */ public static final String VERSION = "version"; - private Spdy2HttpNames() { - super(); - } + private Spdy2HttpNames() { } } diff --git a/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyHttpDecoder.java b/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyHttpDecoder.java index 2166b962a5..9c6deeb7e2 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyHttpDecoder.java +++ b/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyHttpDecoder.java @@ -52,7 +52,6 @@ public class SpdyHttpDecoder extends MessageToMessageDecoder SpdyConstants.SPDY_MAX_VERSION) { throw new IllegalArgumentException( "unsupported version: " + version); diff --git a/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyHttpHeaders.java b/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyHttpHeaders.java index 003d77f952..2bf876b855 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyHttpHeaders.java +++ b/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyHttpHeaders.java @@ -51,9 +51,7 @@ public final class SpdyHttpHeaders { */ public static final String SCHEME = "X-SPDY-Scheme"; - private Names() { - super(); - } + private Names() { } } private SpdyHttpHeaders() { diff --git a/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyProtocolException.java b/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyProtocolException.java index f18d4c8732..cadd9dabcb 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyProtocolException.java +++ b/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyProtocolException.java @@ -27,9 +27,7 @@ public class SpdyProtocolException extends Exception { /** * Creates a new instance. */ - public SpdyProtocolException() { - super(); - } + public SpdyProtocolException() { } /** * Creates a new instance. diff --git a/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdySession.java b/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdySession.java index dbdbbeecc2..5015740c6a 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdySession.java +++ b/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdySession.java @@ -259,11 +259,6 @@ final class SpdySession { } private final class PriorityComparator implements Comparator { - - public PriorityComparator() { - super(); - } - @Override public int compare(Integer id1, Integer id2) { StreamState state1 = activeStreams.get(id1); diff --git a/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdySessionHandler.java b/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdySessionHandler.java index 7c1ab6dd99..4f96c0da54 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdySessionHandler.java +++ b/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdySessionHandler.java @@ -77,7 +77,6 @@ public class SpdySessionHandler * handle the client endpoint of the connection. */ public SpdySessionHandler(int version, boolean server) { - super(); if (version < SpdyConstants.SPDY_MIN_VERSION || version > SpdyConstants.SPDY_MAX_VERSION) { throw new IllegalArgumentException( "unsupported version: " + version); diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/CookieDecoderTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/CookieDecoderTest.java index f1643e06bc..adfb0b6361 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/CookieDecoderTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/CookieDecoderTest.java @@ -15,7 +15,7 @@ */ package io.netty.handler.codec.http; -import static org.junit.Assert.*; +import org.junit.Test; import java.util.Calendar; import java.util.Date; @@ -23,7 +23,7 @@ import java.util.Iterator; import java.util.Set; import java.util.TimeZone; -import org.junit.Test; +import static org.junit.Assert.*; public class CookieDecoderTest { @Test @@ -350,7 +350,7 @@ public class CookieDecoderTest { @Test public void testDecodingLongDates() { Calendar cookieDate = Calendar.getInstance(TimeZone.getTimeZone("UTC")); - cookieDate.set(9999, 11, 31, 23, 59, 59); + cookieDate.set(9999, Calendar.DECEMBER, 31, 23, 59, 59); long expectedMaxAge = (cookieDate.getTimeInMillis() - System.currentTimeMillis()) / 1000; String source = "Format=EU; expires=Fri, 31-Dec-9999 23:59:59 GMT; path=/"; diff --git a/codec-http/src/test/java/io/netty/handler/codec/spdy/SpdySessionHandlerTest.java b/codec-http/src/test/java/io/netty/handler/codec/spdy/SpdySessionHandlerTest.java index 3f24939cd3..36fba66a74 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/spdy/SpdySessionHandlerTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/spdy/SpdySessionHandlerTest.java @@ -20,13 +20,12 @@ import io.netty.channel.ChannelInboundMessageHandlerAdapter; import io.netty.channel.embedded.EmbeddedMessageChannel; import io.netty.logging.InternalLogger; import io.netty.logging.InternalLoggerFactory; +import org.junit.Assert; +import org.junit.Test; import java.util.List; import java.util.Map; -import org.junit.Assert; -import org.junit.Test; - public class SpdySessionHandlerTest { private static final InternalLogger logger = @@ -278,7 +277,6 @@ public class SpdySessionHandlerTest { private final boolean server; EchoHandler(int closeSignal, boolean server) { - super(); this.closeSignal = closeSignal; this.server = server; } diff --git a/codec/src/main/java/io/netty/handler/codec/PrematureChannelClosureException.java b/codec/src/main/java/io/netty/handler/codec/PrematureChannelClosureException.java index 3845829647..22940f750c 100644 --- a/codec/src/main/java/io/netty/handler/codec/PrematureChannelClosureException.java +++ b/codec/src/main/java/io/netty/handler/codec/PrematureChannelClosureException.java @@ -29,9 +29,7 @@ public class PrematureChannelClosureException extends CodecException { /** * Creates a new instance. */ - public PrematureChannelClosureException() { - super(); - } + public PrematureChannelClosureException() { } /** * Creates a new instance. diff --git a/codec/src/main/java/io/netty/handler/codec/ReplayingDecoder.java b/codec/src/main/java/io/netty/handler/codec/ReplayingDecoder.java index 7ec1aaf860..3e0b631f85 100644 --- a/codec/src/main/java/io/netty/handler/codec/ReplayingDecoder.java +++ b/codec/src/main/java/io/netty/handler/codec/ReplayingDecoder.java @@ -297,7 +297,7 @@ public abstract class ReplayingDecoder> extends ByteToMessa * Creates a new instance with the specified initial state. */ protected ReplayingDecoder(S initialState) { - this.state = initialState; + state = initialState; } /** diff --git a/codec/src/main/java/io/netty/handler/codec/ReplayingDecoderBuffer.java b/codec/src/main/java/io/netty/handler/codec/ReplayingDecoderBuffer.java index a0a2f3db5a..5d75346f6b 100644 --- a/codec/src/main/java/io/netty/handler/codec/ReplayingDecoderBuffer.java +++ b/codec/src/main/java/io/netty/handler/codec/ReplayingDecoderBuffer.java @@ -39,7 +39,7 @@ class ReplayingDecoderBuffer implements ByteBuf { private final SwappedByteBuf swapped; private boolean terminated; - public static ReplayingDecoderBuffer EMPTY_BUFFER = new ReplayingDecoderBuffer(Unpooled.EMPTY_BUFFER); + static final ReplayingDecoderBuffer EMPTY_BUFFER = new ReplayingDecoderBuffer(Unpooled.EMPTY_BUFFER); static { EMPTY_BUFFER.terminate(); diff --git a/codec/src/main/java/io/netty/handler/codec/UnsupportedMessageTypeException.java b/codec/src/main/java/io/netty/handler/codec/UnsupportedMessageTypeException.java index 5b64316e41..b923f5ed1b 100644 --- a/codec/src/main/java/io/netty/handler/codec/UnsupportedMessageTypeException.java +++ b/codec/src/main/java/io/netty/handler/codec/UnsupportedMessageTypeException.java @@ -25,9 +25,7 @@ public class UnsupportedMessageTypeException extends CodecException { message == null? "null" : message.getClass().getName(), expectedTypes)); } - public UnsupportedMessageTypeException() { - super(); - } + public UnsupportedMessageTypeException() { } public UnsupportedMessageTypeException(String message, Throwable cause) { super(message, cause); diff --git a/codec/src/main/java/io/netty/handler/codec/base64/Base64.java b/codec/src/main/java/io/netty/handler/codec/base64/Base64.java index b95f9ae493..1c5ba5ebf8 100644 --- a/codec/src/main/java/io/netty/handler/codec/base64/Base64.java +++ b/codec/src/main/java/io/netty/handler/codec/base64/Base64.java @@ -296,9 +296,9 @@ public final class Base64 { byte[] b4 = new byte[4]; int b4Posn = 0; - int i = 0; - byte sbiCrop = 0; - byte sbiDecode = 0; + int i; + byte sbiCrop; + byte sbiDecode; for (i = off; i < off + len; i ++) { sbiCrop = (byte) (src.getByte(i) & 0x7f); // Only the low seven bits sbiDecode = DECODABET[sbiCrop]; diff --git a/codec/src/main/java/io/netty/handler/codec/compression/ZlibEncoder.java b/codec/src/main/java/io/netty/handler/codec/compression/ZlibEncoder.java index 72dae4e1ee..b5e559d811 100644 --- a/codec/src/main/java/io/netty/handler/codec/compression/ZlibEncoder.java +++ b/codec/src/main/java/io/netty/handler/codec/compression/ZlibEncoder.java @@ -294,8 +294,7 @@ public class ZlibEncoder extends ByteToByteEncoder { z.next_out = out.array(); z.next_out_index = out.arrayOffset() + out.writerIndex(); } else { - byte[] array = new byte[maxOutputLength]; - z.next_out = array; + z.next_out = new byte[maxOutputLength]; z.next_out_index = 0; } int oldNextOutIndex = z.next_out_index; diff --git a/codec/src/main/java/io/netty/handler/codec/marshalling/CompatibleMarshallingDecoder.java b/codec/src/main/java/io/netty/handler/codec/marshalling/CompatibleMarshallingDecoder.java index ac91c32c74..4bced65369 100644 --- a/codec/src/main/java/io/netty/handler/codec/marshalling/CompatibleMarshallingDecoder.java +++ b/codec/src/main/java/io/netty/handler/codec/marshalling/CompatibleMarshallingDecoder.java @@ -21,12 +21,11 @@ import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.ReplayingDecoder; import io.netty.handler.codec.TooLongFrameException; import io.netty.util.VoidEnum; - -import java.io.ObjectStreamConstants; - import org.jboss.marshalling.ByteInput; import org.jboss.marshalling.Unmarshaller; +import java.io.ObjectStreamConstants; + /** * {@link ReplayingDecoder} which use an {@link Unmarshaller} to read the Object out of the {@link ByteBuf}. * @@ -88,8 +87,7 @@ public class CompatibleMarshallingDecoder extends ReplayingDecoder * - * @see com.google.protobuf.CodedInputStream + * @see CodedInputStream */ public class ProtobufVarint32FrameDecoder extends ByteToMessageDecoder { diff --git a/codec/src/main/java/io/netty/handler/codec/protobuf/ProtobufVarint32LengthFieldPrepender.java b/codec/src/main/java/io/netty/handler/codec/protobuf/ProtobufVarint32LengthFieldPrepender.java index 64bda43c77..98ecb47113 100644 --- a/codec/src/main/java/io/netty/handler/codec/protobuf/ProtobufVarint32LengthFieldPrepender.java +++ b/codec/src/main/java/io/netty/handler/codec/protobuf/ProtobufVarint32LengthFieldPrepender.java @@ -35,7 +35,7 @@ import com.google.protobuf.CodedOutputStream; * +---------------+ +--------+---------------+ * * * - * @see com.google.protobuf.CodedOutputStream + * @see CodedOutputStream */ @Sharable public class ProtobufVarint32LengthFieldPrepender extends MessageToByteEncoder { @@ -54,8 +54,7 @@ public class ProtobufVarint32LengthFieldPrepender extends MessageToByteEncoder= 0; + IS_WINDOWS = os.contains("win"); } /** diff --git a/common/src/main/java/io/netty/util/internal/StringUtil.java b/common/src/main/java/io/netty/util/internal/StringUtil.java index f0c03c6f30..a82e7af4d9 100644 --- a/common/src/main/java/io/netty/util/internal/StringUtil.java +++ b/common/src/main/java/io/netty/util/internal/StringUtil.java @@ -29,7 +29,7 @@ public final class StringUtil { public static final String NEWLINE; static { - String newLine = null; + String newLine; try { newLine = new Formatter().format("%n").toString(); diff --git a/example/src/main/java/io/netty/example/http/websocketx/sslserver/WebSocketSslServerSslContext.java b/example/src/main/java/io/netty/example/http/websocketx/sslserver/WebSocketSslServerSslContext.java index 0ef93ea242..18baa69cdd 100644 --- a/example/src/main/java/io/netty/example/http/websocketx/sslserver/WebSocketSslServerSslContext.java +++ b/example/src/main/java/io/netty/example/http/websocketx/sslserver/WebSocketSslServerSslContext.java @@ -18,13 +18,12 @@ package io.netty.example.http.websocketx.sslserver; import io.netty.logging.InternalLogger; import io.netty.logging.InternalLoggerFactory; +import javax.net.ssl.KeyManagerFactory; +import javax.net.ssl.SSLContext; import java.io.FileInputStream; import java.security.KeyStore; import java.security.Security; -import javax.net.ssl.KeyManagerFactory; -import javax.net.ssl.SSLContext; - /** * Creates a {@link SSLContext} for just server certificates. */ @@ -48,7 +47,6 @@ public final class WebSocketSslServerSslContext { * See http://en.wikipedia.org/wiki/Singleton_pattern */ private static class SingletonHolder { - public static final WebSocketSslServerSslContext INSTANCE = new WebSocketSslServerSslContext(); } @@ -63,7 +61,7 @@ public final class WebSocketSslServerSslContext { algorithm = "SunX509"; } - SSLContext serverContext = null; + SSLContext serverContext; try { String keyStoreFilePath = System.getProperty("keystore.file.path"); String keyStoreFilePassword = System.getProperty("keystore.file.password"); diff --git a/example/src/main/java/io/netty/example/securechat/SecureChatSslContextFactory.java b/example/src/main/java/io/netty/example/securechat/SecureChatSslContextFactory.java index f9dca7cc0a..aa72ab28e0 100644 --- a/example/src/main/java/io/netty/example/securechat/SecureChatSslContextFactory.java +++ b/example/src/main/java/io/netty/example/securechat/SecureChatSslContextFactory.java @@ -17,15 +17,14 @@ package io.netty.example.securechat; import io.netty.handler.ssl.SslHandler; -import java.security.KeyStore; -import java.security.SecureRandom; -import java.security.Security; - import javax.net.ssl.KeyManager; import javax.net.ssl.KeyManagerFactory; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLEngine; import javax.net.ssl.TrustManager; +import java.security.KeyStore; +import java.security.SecureRandom; +import java.security.Security; /** * Creates a bogus {@link SSLContext}. A client-side context created by this @@ -62,8 +61,8 @@ public final class SecureChatSslContextFactory { algorithm = "SunX509"; } - SSLContext serverContext = null; - SSLContext clientContext = null; + SSLContext serverContext; + SSLContext clientContext; try { KeyStore ks = KeyStore.getInstance("JKS"); ks.load(SecureChatKeyStore.asInputStream(), diff --git a/handler/src/main/java/io/netty/handler/logging/ByteLoggingHandler.java b/handler/src/main/java/io/netty/handler/logging/ByteLoggingHandler.java index afd99afcaf..a3a7362e64 100644 --- a/handler/src/main/java/io/netty/handler/logging/ByteLoggingHandler.java +++ b/handler/src/main/java/io/netty/handler/logging/ByteLoggingHandler.java @@ -85,9 +85,7 @@ public class ByteLoggingHandler } } - public ByteLoggingHandler() { - super(); - } + public ByteLoggingHandler() { } public ByteLoggingHandler(Class clazz, LogLevel level) { super(clazz, level); diff --git a/handler/src/main/java/io/netty/handler/logging/MessageLoggingHandler.java b/handler/src/main/java/io/netty/handler/logging/MessageLoggingHandler.java index f238ce2b94..c4df1fc915 100644 --- a/handler/src/main/java/io/netty/handler/logging/MessageLoggingHandler.java +++ b/handler/src/main/java/io/netty/handler/logging/MessageLoggingHandler.java @@ -28,9 +28,7 @@ public class MessageLoggingHandler extends LoggingHandler implements ChannelInboundMessageHandler, ChannelOutboundMessageHandler { - public MessageLoggingHandler() { - super(); - } + public MessageLoggingHandler() { } public MessageLoggingHandler(Class clazz, LogLevel level) { super(clazz, level); diff --git a/handler/src/main/java/io/netty/handler/ssl/SslHandler.java b/handler/src/main/java/io/netty/handler/ssl/SslHandler.java index 6c40d750b8..0323985dd3 100644 --- a/handler/src/main/java/io/netty/handler/ssl/SslHandler.java +++ b/handler/src/main/java/io/netty/handler/ssl/SslHandler.java @@ -344,7 +344,7 @@ public class SslHandler boolean unwrapLater = false; int bytesProduced = 0; try { - loop: for (;;) { + for (;;) { SSLEngineResult result = wrap(engine, in, out); bytesProduced += result.bytesProduced(); if (result.getStatus() == Status.CLOSED) { @@ -380,7 +380,7 @@ public class SslHandler } if (result.bytesConsumed() == 0 && result.bytesProduced() == 0) { - break loop; + break; } } } @@ -503,7 +503,7 @@ public class SslHandler } if (result.bytesConsumed() == 0 && result.bytesProduced() == 0) { - break loop; + break; } } diff --git a/handler/src/main/java/io/netty/handler/stream/ChunkedNioFile.java b/handler/src/main/java/io/netty/handler/stream/ChunkedNioFile.java index b346442244..aeb2500cc4 100644 --- a/handler/src/main/java/io/netty/handler/stream/ChunkedNioFile.java +++ b/handler/src/main/java/io/netty/handler/stream/ChunkedNioFile.java @@ -33,7 +33,7 @@ import java.nio.channels.FileChannel; public class ChunkedNioFile implements ChunkedByteInput { private final FileChannel in; - private long startOffset; + private final long startOffset; private final long endOffset; private final int chunkSize; private long offset; diff --git a/handler/src/main/java/io/netty/handler/stream/ChunkedWriteHandler.java b/handler/src/main/java/io/netty/handler/stream/ChunkedWriteHandler.java index c7d3d9aa1f..83bbaa6f71 100644 --- a/handler/src/main/java/io/netty/handler/stream/ChunkedWriteHandler.java +++ b/handler/src/main/java/io/netty/handler/stream/ChunkedWriteHandler.java @@ -35,7 +35,7 @@ import java.util.concurrent.atomic.AtomicInteger; /** * A {@link ChannelHandler} that adds support for writing a large data stream * asynchronously neither spending a lot of memory nor getting - * {@link java.lang.OutOfMemoryError}. Large data streaming such as file + * {@link OutOfMemoryError}. Large data streaming such as file * transfer requires complicated state management in a {@link ChannelHandler} * implementation. {@link ChunkedWriteHandler} manages such complicated states * so that you can send a large data stream without difficulties. @@ -71,7 +71,6 @@ public class ChunkedWriteHandler private static final InternalLogger logger = InternalLoggerFactory.getInstance(ChunkedWriteHandler.class); - private final MessageBuf queue = Unpooled.messageBuffer(); private final int maxPendingWrites; private volatile ChannelHandlerContext ctx; diff --git a/testsuite/src/test/java/io/netty/testsuite/transport/socket/DatagramMulticastTest.java b/testsuite/src/test/java/io/netty/testsuite/transport/socket/DatagramMulticastTest.java index 3e02046fa3..e07c2a77b5 100644 --- a/testsuite/src/test/java/io/netty/testsuite/transport/socket/DatagramMulticastTest.java +++ b/testsuite/src/test/java/io/netty/testsuite/transport/socket/DatagramMulticastTest.java @@ -15,7 +15,6 @@ */ package io.netty.testsuite.transport.socket; -import static org.junit.Assert.*; import io.netty.bootstrap.Bootstrap; import io.netty.buffer.Unpooled; import io.netty.channel.Channel; @@ -25,13 +24,14 @@ import io.netty.channel.ChannelOption; import io.netty.channel.socket.DatagramChannel; import io.netty.channel.socket.DatagramPacket; import io.netty.util.NetworkConstants; +import org.junit.Assert; +import org.junit.Test; import java.net.InetSocketAddress; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; -import org.junit.Assert; -import org.junit.Test; +import static org.junit.Assert.*; public class DatagramMulticastTest extends AbstractDatagramTest { @@ -89,8 +89,8 @@ public class DatagramMulticastTest extends AbstractDatagramTest { private final class MulticastTestHandler extends ChannelInboundMessageHandlerAdapter { private final CountDownLatch latch = new CountDownLatch(1); - private boolean done = false; - private volatile boolean fail = false; + private boolean done; + private volatile boolean fail; @Override public void messageReceived( diff --git a/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketSslEchoTest.java b/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketSslEchoTest.java index a9a040daaf..2893b7b7fc 100644 --- a/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketSslEchoTest.java +++ b/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketSslEchoTest.java @@ -15,7 +15,6 @@ */ package io.netty.testsuite.transport.socket; -import static org.junit.Assert.*; import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.ServerBootstrap; import io.netty.buffer.ByteBuf; @@ -27,7 +26,15 @@ import io.netty.channel.ChannelInboundByteHandlerAdapter; import io.netty.channel.ChannelInitializer; import io.netty.channel.socket.SocketChannel; import io.netty.handler.ssl.SslHandler; +import org.junit.Test; +import javax.net.ssl.KeyManagerFactory; +import javax.net.ssl.ManagerFactoryParameters; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLEngine; +import javax.net.ssl.TrustManager; +import javax.net.ssl.TrustManagerFactorySpi; +import javax.net.ssl.X509TrustManager; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; @@ -40,15 +47,7 @@ import java.security.cert.X509Certificate; import java.util.Random; import java.util.concurrent.atomic.AtomicReference; -import javax.net.ssl.KeyManagerFactory; -import javax.net.ssl.ManagerFactoryParameters; -import javax.net.ssl.SSLContext; -import javax.net.ssl.SSLEngine; -import javax.net.ssl.TrustManager; -import javax.net.ssl.TrustManagerFactorySpi; -import javax.net.ssl.X509TrustManager; - -import org.junit.Test; +import static org.junit.Assert.*; public class SocketSslEchoTest extends AbstractSocketTest { @@ -209,8 +208,8 @@ public class SocketSslEchoTest extends AbstractSocketTest { algorithm = "SunX509"; } - SSLContext serverContext = null; - SSLContext clientContext = null; + SSLContext serverContext; + SSLContext clientContext; try { KeyStore ks = KeyStore.getInstance("JKS"); ks.load(BogusKeyStore.asInputStream(), @@ -250,7 +249,7 @@ public class SocketSslEchoTest extends AbstractSocketTest { } /** - * Bogus {@link javax.net.ssl.TrustManagerFactorySpi} which accepts any certificate + * Bogus {@link TrustManagerFactorySpi} which accepts any certificate * even if it is invalid. */ private static class BogusTrustManagerFactory extends TrustManagerFactorySpi { diff --git a/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketTestPermutation.java b/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketTestPermutation.java index b7d04c6356..9e94f64638 100644 --- a/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketTestPermutation.java +++ b/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketTestPermutation.java @@ -152,7 +152,7 @@ final class SocketTestPermutation { } private SocketTestPermutation() {} - static interface Factory { + interface Factory { T newInstance(); } } diff --git a/testsuite/src/test/java/io/netty/testsuite/util/TestUtils.java b/testsuite/src/test/java/io/netty/testsuite/util/TestUtils.java index 589c417443..f000b4b7a4 100644 --- a/testsuite/src/test/java/io/netty/testsuite/util/TestUtils.java +++ b/testsuite/src/test/java/io/netty/testsuite/util/TestUtils.java @@ -22,7 +22,7 @@ public class TestUtils { private final static int START_PORT = 20000; private final static int END_PORT = 30000; - + /** * Return a free port which can be used to bind to * @@ -42,4 +42,6 @@ public class TestUtils { } throw new RuntimeException("Unable to find a free port...."); } + + private TestUtils() { } } \ No newline at end of file diff --git a/transport/src/main/java/io/netty/bootstrap/ServerBootstrap.java b/transport/src/main/java/io/netty/bootstrap/ServerBootstrap.java index 354bd4acfd..96b95b51c0 100644 --- a/transport/src/main/java/io/netty/bootstrap/ServerBootstrap.java +++ b/transport/src/main/java/io/netty/bootstrap/ServerBootstrap.java @@ -167,6 +167,13 @@ public class ServerBootstrap { return future; } + try { + channel.config().setOptions(parentOptions); + } catch (Exception e) { + future.setFailure(e); + return future; + } + ChannelPipeline p = channel.pipeline(); if (handler != null) { p.addLast(handler); diff --git a/transport/src/main/java/io/netty/channel/AbstractChannel.java b/transport/src/main/java/io/netty/channel/AbstractChannel.java index e194a31eb7..9183d0f24b 100644 --- a/transport/src/main/java/io/netty/channel/AbstractChannel.java +++ b/transport/src/main/java/io/netty/channel/AbstractChannel.java @@ -728,18 +728,18 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha return; } - final long writeCounter = AbstractChannel.this.writeCounter; + final long writeCounter = this.writeCounter; for (;;) { FlushCheckpoint cp = flushCheckpoints.peek(); if (cp == null) { // Reset the counter if there's nothing in the notification list. - AbstractChannel.this.writeCounter = 0; + this.writeCounter = 0; break; } if (cp.flushCheckpoint() > writeCounter) { if (writeCounter > 0 && flushCheckpoints.size() == 1) { - AbstractChannel.this.writeCounter = 0; + this.writeCounter = 0; cp.flushCheckpoint(cp.flushCheckpoint() - writeCounter); } break; @@ -750,11 +750,11 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha } // Avoid overflow - final long newWriteCounter = AbstractChannel.this.writeCounter; + final long newWriteCounter = this.writeCounter; if (newWriteCounter >= 0x1000000000000000L) { // Reset the counter only when the counter grew pretty large // so that we can reduce the cost of updating all entries in the notification list. - AbstractChannel.this.writeCounter = 0; + this.writeCounter = 0; for (FlushCheckpoint cp: flushCheckpoints) { cp.flushCheckpoint(cp.flushCheckpoint() - newWriteCounter); } diff --git a/transport/src/main/java/io/netty/channel/Channel.java b/transport/src/main/java/io/netty/channel/Channel.java index 9fc812fea1..1b149273bd 100644 --- a/transport/src/main/java/io/netty/channel/Channel.java +++ b/transport/src/main/java/io/netty/channel/Channel.java @@ -178,7 +178,7 @@ public interface Channel extends AttributeMap, ChannelOutboundInvoker, ChannelFu Unsafe unsafe(); - public interface Unsafe { + interface Unsafe { ChannelHandlerContext directOutboundContext(); ChannelFuture voidFuture(); diff --git a/transport/src/main/java/io/netty/channel/ChannelBufferType.java b/transport/src/main/java/io/netty/channel/ChannelBufferType.java index 237e559903..6bfcc3db95 100644 --- a/transport/src/main/java/io/netty/channel/ChannelBufferType.java +++ b/transport/src/main/java/io/netty/channel/ChannelBufferType.java @@ -17,5 +17,5 @@ package io.netty.channel; public enum ChannelBufferType { BYTE, - MESSAGE; + MESSAGE } diff --git a/transport/src/main/java/io/netty/channel/ChannelHandlerType.java b/transport/src/main/java/io/netty/channel/ChannelHandlerType.java index 54c3675cad..6ac2f07116 100644 --- a/transport/src/main/java/io/netty/channel/ChannelHandlerType.java +++ b/transport/src/main/java/io/netty/channel/ChannelHandlerType.java @@ -23,7 +23,7 @@ public enum ChannelHandlerType { final int direction; // 0 - up (inbound), 1 - down (outbound) - private ChannelHandlerType(int direction) { + ChannelHandlerType(int direction) { this.direction = direction; } } diff --git a/transport/src/main/java/io/netty/channel/DefaultChannelFuture.java b/transport/src/main/java/io/netty/channel/DefaultChannelFuture.java index 24196b88dd..4dfdba1ecc 100644 --- a/transport/src/main/java/io/netty/channel/DefaultChannelFuture.java +++ b/transport/src/main/java/io/netty/channel/DefaultChannelFuture.java @@ -209,7 +209,7 @@ public class DefaultChannelFuture extends FlushCheckpoint implements ChannelFutu checkDeadLock(); waiters++; try { - this.wait(); + wait(); } finally { waiters--; } @@ -237,7 +237,7 @@ public class DefaultChannelFuture extends FlushCheckpoint implements ChannelFutu checkDeadLock(); waiters++; try { - this.wait(); + wait(); } catch (InterruptedException e) { interrupted = true; } finally { @@ -293,7 +293,7 @@ public class DefaultChannelFuture extends FlushCheckpoint implements ChannelFutu try { for (;;) { try { - this.wait(waitTime / 1000000, (int) (waitTime % 1000000)); + wait(waitTime / 1000000, (int) (waitTime % 1000000)); } catch (InterruptedException e) { if (interruptable) { throw e; diff --git a/transport/src/main/java/io/netty/channel/DefaultChannelHandlerContext.java b/transport/src/main/java/io/netty/channel/DefaultChannelHandlerContext.java index 7feab0fbf1..3802092c39 100644 --- a/transport/src/main/java/io/netty/channel/DefaultChannelHandlerContext.java +++ b/transport/src/main/java/io/netty/channel/DefaultChannelHandlerContext.java @@ -15,7 +15,6 @@ */ package io.netty.channel; -import static io.netty.channel.DefaultChannelPipeline.*; import io.netty.buffer.ByteBuf; import io.netty.buffer.ChannelBuf; import io.netty.buffer.MessageBuf; @@ -30,6 +29,8 @@ import java.util.Set; import java.util.concurrent.BlockingQueue; import java.util.concurrent.atomic.AtomicReference; +import static io.netty.channel.DefaultChannelPipeline.*; + final class DefaultChannelHandlerContext extends DefaultAttributeMap implements ChannelHandlerContext { private static final EnumSet EMPTY_TYPE = EnumSet.noneOf(ChannelHandlerType.class); @@ -757,9 +758,7 @@ final class DefaultChannelHandlerContext extends DefaultAttributeMap implements break; } - for (Object d: data) { - out.add(d); - } + Collections.addAll(out, data); } } } diff --git a/transport/src/main/java/io/netty/channel/EventExecutor.java b/transport/src/main/java/io/netty/channel/EventExecutor.java index 0e595465a7..eb96c88122 100644 --- a/transport/src/main/java/io/netty/channel/EventExecutor.java +++ b/transport/src/main/java/io/netty/channel/EventExecutor.java @@ -22,7 +22,7 @@ public interface EventExecutor extends ScheduledExecutorService { boolean inEventLoop(Thread thread); Unsafe unsafe(); - public interface Unsafe { + interface Unsafe { EventExecutor nextChild(); } } diff --git a/transport/src/main/java/io/netty/channel/SingleThreadEventExecutor.java b/transport/src/main/java/io/netty/channel/SingleThreadEventExecutor.java index 9dff1f83ad..4615b1fc90 100644 --- a/transport/src/main/java/io/netty/channel/SingleThreadEventExecutor.java +++ b/transport/src/main/java/io/netty/channel/SingleThreadEventExecutor.java @@ -514,8 +514,8 @@ public abstract class SingleThreadEventExecutor extends AbstractExecutorService ScheduledFutureTask(Runnable runnable, V result, long nanoTime) { super(runnable, result); - this.deadlineNanos = nanoTime; - this.periodNanos = 0; + deadlineNanos = nanoTime; + periodNanos = 0; } ScheduledFutureTask(Runnable runnable, V result, long nanoTime, long period) { @@ -524,14 +524,14 @@ public abstract class SingleThreadEventExecutor extends AbstractExecutorService throw new IllegalArgumentException( String.format("period: %d (expected: != 0)", period)); } - this.deadlineNanos = nanoTime; - this.periodNanos = period; + deadlineNanos = nanoTime; + periodNanos = period; } ScheduledFutureTask(Callable callable, long nanoTime) { super(callable); - this.deadlineNanos = nanoTime; - this.periodNanos = 0; + deadlineNanos = nanoTime; + periodNanos = 0; } public long deadlineNanos() { diff --git a/transport/src/main/java/io/netty/channel/embedded/AbstractEmbeddedChannel.java b/transport/src/main/java/io/netty/channel/embedded/AbstractEmbeddedChannel.java index 05a9e16852..3db503aa4f 100644 --- a/transport/src/main/java/io/netty/channel/embedded/AbstractEmbeddedChannel.java +++ b/transport/src/main/java/io/netty/channel/embedded/AbstractEmbeddedChannel.java @@ -41,7 +41,6 @@ public abstract class AbstractEmbeddedChannel extends AbstractChannel { private static final InternalLogger logger = InternalLoggerFactory.getInstance(AbstractEmbeddedChannel.class); - private final EmbeddedEventLoop loop = new EmbeddedEventLoop(); private final ChannelConfig config = new DefaultChannelConfig(); private final SocketAddress localAddress = new EmbeddedSocketAddress(); private final SocketAddress remoteAddress = new EmbeddedSocketAddress(); @@ -83,7 +82,7 @@ public abstract class AbstractEmbeddedChannel extends AbstractChannel { } p.addLast(new LastInboundMessageHandler(), new LastInboundByteHandler()); - loop.register(this); + new EmbeddedEventLoop().register(this); } @Override diff --git a/transport/src/main/java/io/netty/channel/group/DefaultChannelGroupFuture.java b/transport/src/main/java/io/netty/channel/group/DefaultChannelGroupFuture.java index a22b5b3cd3..06d30d35db 100644 --- a/transport/src/main/java/io/netty/channel/group/DefaultChannelGroupFuture.java +++ b/transport/src/main/java/io/netty/channel/group/DefaultChannelGroupFuture.java @@ -15,7 +15,6 @@ */ package io.netty.channel.group; -import static java.util.concurrent.TimeUnit.*; import io.netty.channel.Channel; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFutureListener; @@ -32,6 +31,8 @@ import java.util.List; import java.util.Map; import java.util.concurrent.TimeUnit; +import static java.util.concurrent.TimeUnit.*; + /** * The default {@link ChannelGroupFuture} implementation. */ @@ -53,7 +54,7 @@ public class DefaultChannelGroupFuture implements ChannelGroupFuture { @Override public void operationComplete(ChannelFuture future) throws Exception { boolean success = future.isSuccess(); - boolean callSetDone = false; + boolean callSetDone; synchronized (DefaultChannelGroupFuture.this) { if (success) { successCount ++; @@ -219,7 +220,7 @@ public class DefaultChannelGroupFuture implements ChannelGroupFuture { checkDeadLock(); waiters++; try { - this.wait(); + wait(); } finally { waiters--; } @@ -247,7 +248,7 @@ public class DefaultChannelGroupFuture implements ChannelGroupFuture { checkDeadLock(); waiters++; try { - this.wait(); + wait(); } catch (InterruptedException e) { interrupted = true; } finally { @@ -303,7 +304,7 @@ public class DefaultChannelGroupFuture implements ChannelGroupFuture { try { for (;;) { try { - this.wait(waitTime / 1000000, (int) (waitTime % 1000000)); + wait(waitTime / 1000000, (int) (waitTime % 1000000)); } catch (InterruptedException e) { if (interruptable) { throw e; @@ -341,11 +342,11 @@ public class DefaultChannelGroupFuture implements ChannelGroupFuture { } } - boolean setDone() { + void setDone() { synchronized (this) { // Allow only once. if (done) { - return false; + return; } done = true; @@ -355,7 +356,6 @@ public class DefaultChannelGroupFuture implements ChannelGroupFuture { } notifyListeners(); - return true; } private void notifyListeners() { diff --git a/transport/src/main/java/io/netty/channel/local/LocalChannel.java b/transport/src/main/java/io/netty/channel/local/LocalChannel.java index 1e5a981f2c..9903f3c171 100644 --- a/transport/src/main/java/io/netty/channel/local/LocalChannel.java +++ b/transport/src/main/java/io/netty/channel/local/LocalChannel.java @@ -23,6 +23,7 @@ import io.netty.channel.ChannelException; import io.netty.channel.ChannelFuture; import io.netty.channel.DefaultChannelConfig; import io.netty.channel.EventLoop; +import io.netty.channel.SingleThreadEventExecutor; import io.netty.channel.SingleThreadEventLoop; import java.net.SocketAddress; @@ -152,7 +153,7 @@ public class LocalChannel extends AbstractChannel { postRegisterTask = null; } - ((SingleThreadEventLoop) eventLoop()).addShutdownHook(shutdownHook); + ((SingleThreadEventExecutor) eventLoop()).addShutdownHook(shutdownHook); return postRegisterTask; } @@ -198,7 +199,7 @@ public class LocalChannel extends AbstractChannel { if (isOpen()) { unsafe().close(unsafe().voidFuture()); } - ((SingleThreadEventLoop) eventLoop()).removeShutdownHook(shutdownHook); + ((SingleThreadEventExecutor) eventLoop()).removeShutdownHook(shutdownHook); } @Override diff --git a/transport/src/main/java/io/netty/channel/local/LocalServerChannel.java b/transport/src/main/java/io/netty/channel/local/LocalServerChannel.java index 0aa42207ef..36053e37f9 100644 --- a/transport/src/main/java/io/netty/channel/local/LocalServerChannel.java +++ b/transport/src/main/java/io/netty/channel/local/LocalServerChannel.java @@ -20,6 +20,7 @@ import io.netty.channel.ChannelConfig; import io.netty.channel.DefaultChannelConfig; import io.netty.channel.EventLoop; import io.netty.channel.ServerChannel; +import io.netty.channel.SingleThreadEventExecutor; import io.netty.channel.SingleThreadEventLoop; import java.net.SocketAddress; @@ -85,7 +86,7 @@ public class LocalServerChannel extends AbstractServerChannel { @Override protected Runnable doRegister() throws Exception { - ((SingleThreadEventLoop) eventLoop()).addShutdownHook(shutdownHook); + ((SingleThreadEventExecutor) eventLoop()).addShutdownHook(shutdownHook); return null; } @@ -115,7 +116,7 @@ public class LocalServerChannel extends AbstractServerChannel { @Override protected void doDeregister() throws Exception { - ((SingleThreadEventLoop) eventLoop()).removeShutdownHook(shutdownHook); + ((SingleThreadEventExecutor) eventLoop()).removeShutdownHook(shutdownHook); } LocalChannel serve(final LocalChannel peer) { diff --git a/transport/src/main/java/io/netty/channel/socket/DefaultDatagramChannelConfig.java b/transport/src/main/java/io/netty/channel/socket/DefaultDatagramChannelConfig.java index 895abb3db0..1deaa2c415 100644 --- a/transport/src/main/java/io/netty/channel/socket/DefaultDatagramChannelConfig.java +++ b/transport/src/main/java/io/netty/channel/socket/DefaultDatagramChannelConfig.java @@ -15,7 +15,6 @@ */ package io.netty.channel.socket; -import static io.netty.channel.ChannelOption.*; import io.netty.channel.ChannelException; import io.netty.channel.ChannelOption; import io.netty.channel.DefaultChannelConfig; @@ -28,12 +27,14 @@ import java.net.NetworkInterface; import java.net.SocketException; import java.util.Map; +import static io.netty.channel.ChannelOption.*; + /** * The default {@link DatagramChannelConfig} implementation. */ public class DefaultDatagramChannelConfig extends DefaultChannelConfig implements DatagramChannelConfig { - private static int DEFAULT_RECEIVE_PACKET_SIZE = 2048; + private static final int DEFAULT_RECEIVE_PACKET_SIZE = 2048; private final DatagramSocket socket; private volatile int receivePacketSize = DEFAULT_RECEIVE_PACKET_SIZE; diff --git a/transport/src/main/java/io/netty/channel/socket/InternetProtocolFamily.java b/transport/src/main/java/io/netty/channel/socket/InternetProtocolFamily.java index b9d3f98150..c18273cac1 100644 --- a/transport/src/main/java/io/netty/channel/socket/InternetProtocolFamily.java +++ b/transport/src/main/java/io/netty/channel/socket/InternetProtocolFamily.java @@ -20,5 +20,5 @@ package io.netty.channel.socket; */ public enum InternetProtocolFamily { IPv4, - IPv6; + IPv6 } diff --git a/transport/src/main/java/io/netty/channel/socket/nio/AbstractNioChannel.java b/transport/src/main/java/io/netty/channel/socket/nio/AbstractNioChannel.java index 01f16cca80..5d2f62616d 100644 --- a/transport/src/main/java/io/netty/channel/socket/nio/AbstractNioChannel.java +++ b/transport/src/main/java/io/netty/channel/socket/nio/AbstractNioChannel.java @@ -144,13 +144,9 @@ public abstract class AbstractNioChannel extends AbstractChannel { connectTimeoutException = new ConnectException("connection timed out"); } ChannelFuture connectFuture = AbstractNioChannel.this.connectFuture; - if (connectFuture == null) { - return; - } else { - if (connectFuture.setFailure(connectTimeoutException)) { - pipeline().fireExceptionCaught(connectTimeoutException); - close(voidFuture()); - } + if (connectFuture != null && connectFuture.setFailure(connectTimeoutException)) { + pipeline().fireExceptionCaught(connectTimeoutException); + close(voidFuture()); } } }, connectTimeoutMillis, TimeUnit.MILLISECONDS); diff --git a/transport/src/main/java/io/netty/channel/socket/nio/NioServerSocketChannel.java b/transport/src/main/java/io/netty/channel/socket/nio/NioServerSocketChannel.java index 1405393453..bb02ef536c 100644 --- a/transport/src/main/java/io/netty/channel/socket/nio/NioServerSocketChannel.java +++ b/transport/src/main/java/io/netty/channel/socket/nio/NioServerSocketChannel.java @@ -24,6 +24,7 @@ import java.net.InetSocketAddress; import java.net.SocketAddress; import java.nio.channels.SelectionKey; import java.nio.channels.ServerSocketChannel; +import java.nio.channels.SocketChannel; import java.util.Queue; public class NioServerSocketChannel extends AbstractNioMessageChannel @@ -61,7 +62,7 @@ public class NioServerSocketChannel extends AbstractNioMessageChannel } @Override - protected java.nio.channels.ServerSocketChannel javaChannel() { + protected ServerSocketChannel javaChannel() { return (ServerSocketChannel) super.javaChannel(); } @@ -84,7 +85,7 @@ public class NioServerSocketChannel extends AbstractNioMessageChannel @Override protected int doReadMessages(Queue buf) throws Exception { - java.nio.channels.SocketChannel ch = javaChannel().accept(); + SocketChannel ch = javaChannel().accept(); if (ch == null) { return 0; } diff --git a/transport/src/main/java/io/netty/channel/socket/nio/ProtocolFamilyConverter.java b/transport/src/main/java/io/netty/channel/socket/nio/ProtocolFamilyConverter.java index 08dbdb7a4b..ec8f3665ca 100644 --- a/transport/src/main/java/io/netty/channel/socket/nio/ProtocolFamilyConverter.java +++ b/transport/src/main/java/io/netty/channel/socket/nio/ProtocolFamilyConverter.java @@ -17,6 +17,9 @@ package io.netty.channel.socket.nio; import io.netty.channel.socket.InternetProtocolFamily; +import java.net.ProtocolFamily; +import java.net.StandardProtocolFamily; + /** * Helper class which convert the {@link InternetProtocolFamily}. * @@ -31,13 +34,13 @@ final class ProtocolFamilyConverter { /** * Convert the {@link InternetProtocolFamily}. This MUST only be called on jdk version >= 7. */ - public static java.net.ProtocolFamily convert(InternetProtocolFamily family) { + public static ProtocolFamily convert(InternetProtocolFamily family) { switch (family) { case IPv4: - return java.net.StandardProtocolFamily.INET; + return StandardProtocolFamily.INET; case IPv6: - return java.net.StandardProtocolFamily.INET6; + return StandardProtocolFamily.INET6; default: throw new IllegalArgumentException(); } diff --git a/transport/src/main/java/io/netty/channel/socket/oio/AbstractOioByteChannel.java b/transport/src/main/java/io/netty/channel/socket/oio/AbstractOioByteChannel.java index c429bc81f2..e8c1691071 100644 --- a/transport/src/main/java/io/netty/channel/socket/oio/AbstractOioByteChannel.java +++ b/transport/src/main/java/io/netty/channel/socket/oio/AbstractOioByteChannel.java @@ -73,6 +73,16 @@ abstract class AbstractOioByteChannel extends AbstractOioChannel { } } } + + private void expandReadBuffer(ByteBuf byteBuf) { + int available = available(); + if (available > 0) { + byteBuf.ensureWritableBytes(available); + } else if (!byteBuf.writable()) { + // FIXME: Magic number + byteBuf.ensureWritableBytes(4096); + } + } } @Override @@ -85,15 +95,5 @@ abstract class AbstractOioByteChannel extends AbstractOioChannel { protected abstract int available(); protected abstract int doReadBytes(ByteBuf buf) throws Exception; - protected abstract int doWriteBytes(ByteBuf buf) throws Exception; - - private void expandReadBuffer(ByteBuf byteBuf) { - int available = available(); - if (available > 0) { - byteBuf.ensureWritableBytes(available); - } else if (!byteBuf.writable()) { - // FIXME: Magic number - byteBuf.ensureWritableBytes(4096); - } - } + protected abstract void doWriteBytes(ByteBuf buf) throws Exception; } diff --git a/transport/src/main/java/io/netty/channel/socket/oio/AbstractOioMessageChannel.java b/transport/src/main/java/io/netty/channel/socket/oio/AbstractOioMessageChannel.java index 5bb7da1f3a..dee9359bf3 100644 --- a/transport/src/main/java/io/netty/channel/socket/oio/AbstractOioMessageChannel.java +++ b/transport/src/main/java/io/netty/channel/socket/oio/AbstractOioMessageChannel.java @@ -82,5 +82,5 @@ abstract class AbstractOioMessageChannel extends AbstractOioChannel { } protected abstract int doReadMessages(Queue buf) throws Exception; - protected abstract int doWriteMessages(Queue buf) throws Exception; + protected abstract void doWriteMessages(Queue buf) throws Exception; } diff --git a/transport/src/main/java/io/netty/channel/socket/oio/OioChildEventLoop.java b/transport/src/main/java/io/netty/channel/socket/oio/OioChildEventLoop.java index 9de4268024..917885e78d 100644 --- a/transport/src/main/java/io/netty/channel/socket/oio/OioChildEventLoop.java +++ b/transport/src/main/java/io/netty/channel/socket/oio/OioChildEventLoop.java @@ -48,7 +48,7 @@ class OioChildEventLoop extends SingleThreadEventLoop { @Override protected void run() { for (;;) { - AbstractOioChannel ch = OioChildEventLoop.this.ch; + AbstractOioChannel ch = this.ch; if (ch == null || !ch.isActive()) { Runnable task; try { diff --git a/transport/src/main/java/io/netty/channel/socket/oio/OioDatagramChannel.java b/transport/src/main/java/io/netty/channel/socket/oio/OioDatagramChannel.java index 30db80fb1b..8d6ef5806b 100644 --- a/transport/src/main/java/io/netty/channel/socket/oio/OioDatagramChannel.java +++ b/transport/src/main/java/io/netty/channel/socket/oio/OioDatagramChannel.java @@ -173,7 +173,7 @@ public class OioDatagramChannel extends AbstractOioMessageChannel } @Override - protected int doWriteMessages(Queue buf) throws Exception { + protected void doWriteMessages(Queue buf) throws Exception { DatagramPacket p = (DatagramPacket) buf.poll(); ByteBuf data = p.data(); int length = data.readableBytes(); @@ -187,7 +187,6 @@ public class OioDatagramChannel extends AbstractOioMessageChannel } socket.send(tmpPacket); - return 1; } @Override diff --git a/transport/src/main/java/io/netty/channel/socket/oio/OioEventLoop.java b/transport/src/main/java/io/netty/channel/socket/oio/OioEventLoop.java index d8783b0817..72130dea46 100644 --- a/transport/src/main/java/io/netty/channel/socket/oio/OioEventLoop.java +++ b/transport/src/main/java/io/netty/channel/socket/oio/OioEventLoop.java @@ -270,7 +270,7 @@ public class OioEventLoop implements EventLoop { if (maxChannels > 0 && activeChildren.size() >= maxChannels) { throw tooManyChannels; } - loop = new OioChildEventLoop(OioEventLoop.this); + loop = new OioChildEventLoop(this); } activeChildren.add(loop); return loop; diff --git a/transport/src/main/java/io/netty/channel/socket/oio/OioServerSocketChannel.java b/transport/src/main/java/io/netty/channel/socket/oio/OioServerSocketChannel.java index b2cf3a45e5..15fa6cbf3a 100644 --- a/transport/src/main/java/io/netty/channel/socket/oio/OioServerSocketChannel.java +++ b/transport/src/main/java/io/netty/channel/socket/oio/OioServerSocketChannel.java @@ -169,7 +169,7 @@ public class OioServerSocketChannel extends AbstractOioMessageChannel } @Override - protected int doWriteMessages(Queue buf) throws Exception { + protected void doWriteMessages(Queue buf) throws Exception { throw new UnsupportedOperationException(); } } diff --git a/transport/src/main/java/io/netty/channel/socket/oio/OioSocketChannel.java b/transport/src/main/java/io/netty/channel/socket/oio/OioSocketChannel.java index da67b344e9..390553666d 100644 --- a/transport/src/main/java/io/netty/channel/socket/oio/OioSocketChannel.java +++ b/transport/src/main/java/io/netty/channel/socket/oio/OioSocketChannel.java @@ -159,13 +159,11 @@ public class OioSocketChannel extends AbstractOioByteChannel } @Override - protected int doWriteBytes(ByteBuf buf) throws Exception { + protected void doWriteBytes(ByteBuf buf) throws Exception { OutputStream os = this.os; if (os == null) { throw new NotYetConnectedException(); } - final int length = buf.readableBytes(); - buf.readBytes(os, length); - return length; + buf.readBytes(os, buf.readableBytes()); } } diff --git a/transport/src/test/java/io/netty/channel/local/LocalChannelRegistryTest.java b/transport/src/test/java/io/netty/channel/local/LocalChannelRegistryTest.java index 8516eb2896..55ad59a70f 100644 --- a/transport/src/test/java/io/netty/channel/local/LocalChannelRegistryTest.java +++ b/transport/src/test/java/io/netty/channel/local/LocalChannelRegistryTest.java @@ -32,7 +32,7 @@ public class LocalChannelRegistryTest { private static final InternalLogger logger = InternalLoggerFactory.getInstance(LocalChannelRegistryTest.class); - private static String LOCAL_ADDR_ID = "test.id"; + private static final String LOCAL_ADDR_ID = "test.id"; @Test public void testLocalAddressReuse() throws Exception {