Fix most inspector warnings

Motivation:

It's good to minimize potentially broken windows.

Modifications:

Fix most inspector warnings from our profile
Update IntObjectHashMap

Result:

Cleaner code
This commit is contained in:
Trustin Lee 2014-07-02 19:04:11 +09:00
parent 893bc04eee
commit 0a8ff3b52d
133 changed files with 329 additions and 395 deletions

View File

@ -1,65 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2012 The Netty Project
~
~ The Netty Project 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.
-->
<FindBugsFilter>
<!-- Tests -->
<Match>
<Class name="~.*Test(\$[^\$]+)*"/>
</Match>
<!-- Generated code -->
<Match>
<Class name="~.*\.LocalTimeProtocol(\$[^\$]+)*"/>
</Match>
<!-- Noise -->
<Match>
<Bug code="Co,SF"
category="I18N"
pattern="REC_CATCH_EXCEPTION,UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR,DB_DUPLICATE_SWITCH_CLAUSES,VO_VOLATILE_REFERENCE_TO_ARRAY" />
</Match>
<!-- Known false positives -->
<Match>
<Class name="~.*Channel(Group)?Future"/>
<Method name="~await.*"/>
<Bug pattern="PS_PUBLIC_SEMAPHORES"/>
</Match>
<Match>
<Class name="~.*SelectorLoop"/>
<Method name="run"/>
<Bug code="ESync"/>
</Match>
<Match>
<Class name="~.*Channel"/>
<Or>
<Method name="setClosed"/>
<Method name="setInterestOpsNow"/>
</Or>
<Bug pattern="USM_USELESS_SUBCLASS_METHOD"/>
</Match>
<Match>
<Class name="~.*HttpTunnelingChannelHandler"/>
<Method name="~await.*"/>
<Bug pattern="RV_RETURN_VALUE_IGNORED_BAD_PRACTICE,RV_RETURN_VALUE_IGNORED2"/>
</Match>
<!-- Known issues that don't matter -->
<Match>
<Or>
<Class name="~.*\.util\.internal\.Concurrent[A-Za-z]*HashMap(\$[^\$]+)*"/>
<Class name="~.*\.util\.internal\..*TransferQueue(\$[^\$]+)*"/>
<Class name="~.*\.util\.internal\.MapBackedSet"/>
</Or>
<Bug pattern="SE_TRANSIENT_FIELD_NOT_RESTORED,SE_BAD_FIELD"/>
</Match>
</FindBugsFilter>

View File

@ -37,7 +37,6 @@ public abstract class AbstractReferenceCountedByteBuf extends AbstractByteBuf {
refCntUpdater = updater;
}
@SuppressWarnings("FieldMayBeFinal")
private volatile int refCnt = 1;
protected AbstractReferenceCountedByteBuf(int maxCapacity) {

View File

@ -189,7 +189,7 @@ public class ByteBufInputStream extends InputStream implements DataInput {
loop: while (true) {
if (!buffer.isReadable()) {
return (lineBuf.length() > 0) ? lineBuf.toString() : null;
return lineBuf.length() > 0 ? lineBuf.toString() : null;
}
int c = buffer.readUnsignedByte();
@ -198,7 +198,7 @@ public class ByteBufInputStream extends InputStream implements DataInput {
break loop;
case '\r':
if (buffer.isReadable() && buffer.getUnsignedByte(buffer.readerIndex()) == '\n') {
if (buffer.isReadable() && (char) buffer.getUnsignedByte(buffer.readerIndex()) == '\n') {
buffer.skipBytes(1);
}
break loop;

View File

@ -289,7 +289,6 @@ public class CompositeByteBuf extends AbstractReferenceCountedByteBuf {
ByteBuf consolidated = allocBuffer(capacity);
// We're not using foreach to avoid creating an iterator.
// noinspection ForLoopReplaceableByForEach
for (int i = 0; i < numComponents; i ++) {
Component c = components.get(i);
ByteBuf b = c.buf;
@ -1098,7 +1097,6 @@ public class CompositeByteBuf extends AbstractReferenceCountedByteBuf {
} else {
int count = 0;
int componentsCount = components.size();
//noinspection ForLoopReplaceableByForEach
for (int i = 0; i < componentsCount; i++) {
Component c = components.get(i);
count += c.buf.nioBufferCount();

View File

@ -145,7 +145,6 @@ abstract class PooledByteBuf<T> extends AbstractReferenceCountedByteBuf {
}
}
@SuppressWarnings("unchecked")
private void recycle() {
Recycler.Handle recyclerHandle = this.recyclerHandle;
if (recyclerHandle != null) {

View File

@ -308,7 +308,7 @@ final class PooledDirectByteBuf extends PooledByteBuf<ByteBuffer> {
tmpBuf.clear().position(index).limit(index + length);
try {
return in.read(tmpBuf);
} catch (ClosedChannelException e) {
} catch (ClosedChannelException ignored) {
return -1;
}
}

View File

@ -232,7 +232,7 @@ final class PooledHeapByteBuf extends PooledByteBuf<byte[]> {
index = idx(index);
try {
return in.read((ByteBuffer) internalNioBuffer().clear().position(index).limit(index + length));
} catch (ClosedChannelException e) {
} catch (ClosedChannelException ignored) {
return -1;
}
}

View File

@ -309,7 +309,7 @@ final class PooledUnsafeDirectByteBuf extends PooledByteBuf<ByteBuffer> {
tmpBuf.clear().position(index).limit(index + length);
try {
return in.read(tmpBuf);
} catch (ClosedChannelException e) {
} catch (ClosedChannelException ignored) {
return -1;
}
}

View File

@ -36,7 +36,7 @@ class ReadOnlyByteBufferBuf extends AbstractReferenceCountedByteBuf {
private final ByteBufAllocator allocator;
private ByteBuffer tmpNioBuf;
public ReadOnlyByteBufferBuf(ByteBufAllocator allocator, ByteBuffer buffer) {
ReadOnlyByteBufferBuf(ByteBufAllocator allocator, ByteBuffer buffer) {
super(buffer.remaining());
if (!buffer.isReadOnly()) {
throw new IllegalArgumentException("must be a readonly buffer: " + StringUtil.simpleClassName(buffer));
@ -276,7 +276,7 @@ class ReadOnlyByteBufferBuf extends AbstractReferenceCountedByteBuf {
ByteBuffer src;
try {
src = (ByteBuffer) internalNioBuffer().clear().position(index).limit(index + length);
} catch (IllegalArgumentException e) {
} catch (IllegalArgumentException ignored) {
throw new IndexOutOfBoundsException("Too many bytes to read - Need " + (index + length));
}

View File

@ -30,7 +30,7 @@ final class ReadOnlyUnsafeDirectByteBuf extends ReadOnlyByteBufferBuf {
private static final boolean NATIVE_ORDER = ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN;
private final long memoryAddress;
public ReadOnlyUnsafeDirectByteBuf(ByteBufAllocator allocator, ByteBuffer buffer) {
ReadOnlyUnsafeDirectByteBuf(ByteBufAllocator allocator, ByteBuffer buffer) {
super(allocator, buffer);
memoryAddress = PlatformDependent.directBufferAddress(buffer);
}

View File

@ -39,7 +39,7 @@ public class SlicedByteBuf extends AbstractDerivedByteBuf {
public SlicedByteBuf(ByteBuf buffer, int index, int length) {
super(length);
if (index < 0 || index > buffer.capacity() - length) {
throw new IndexOutOfBoundsException(buffer.toString() + ".slice(" + index + ", " + length + ')');
throw new IndexOutOfBoundsException(buffer + ".slice(" + index + ", " + length + ')');
}
if (buffer instanceof SlicedByteBuf) {

View File

@ -535,7 +535,7 @@ public class UnpooledDirectByteBuf extends AbstractReferenceCountedByteBuf {
tmpBuf.clear().position(index).limit(index + length);
try {
return in.read(tmpNioBuf);
} catch (ClosedChannelException e) {
} catch (ClosedChannelException ignored) {
return -1;
}
}
@ -556,7 +556,7 @@ public class UnpooledDirectByteBuf extends AbstractReferenceCountedByteBuf {
ByteBuffer src;
try {
src = (ByteBuffer) buffer.duplicate().clear().position(index).limit(index + length);
} catch (IllegalArgumentException e) {
} catch (IllegalArgumentException ignored) {
throw new IndexOutOfBoundsException("Too many bytes to read - Need " + (index + length));
}

View File

@ -254,7 +254,7 @@ public class UnpooledHeapByteBuf extends AbstractReferenceCountedByteBuf {
ensureAccessible();
try {
return in.read((ByteBuffer) internalNioBuffer().clear().position(index).limit(index + length));
} catch (ClosedChannelException e) {
} catch (ClosedChannelException ignored) {
return -1;
}
}

View File

@ -444,7 +444,7 @@ public class UnpooledUnsafeDirectByteBuf extends AbstractReferenceCountedByteBuf
tmpBuf.clear().position(index).limit(index + length);
try {
return in.read(tmpBuf);
} catch (ClosedChannelException e) {
} catch (ClosedChannelException ignored) {
return -1;
}
}

View File

@ -773,6 +773,7 @@ class WrappedByteBuf extends ByteBuf {
}
@Override
@SuppressWarnings("EqualsWhichDoesntCheckParameterClass")
public boolean equals(Object obj) {
return buf.equals(obj);
}

View File

@ -18,10 +18,8 @@ package io.netty.buffer;
import io.netty.util.CharsetUtil;
import io.netty.util.IllegalReferenceCountException;
import org.junit.After;
import org.junit.Assert;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import java.io.ByteArrayInputStream;
@ -1477,6 +1475,7 @@ public abstract class AbstractByteBufTest {
}
@Test
@SuppressWarnings("ObjectEqualsNull")
public void testEquals() {
assertFalse(buffer.equals(null));
assertFalse(buffer.equals(new Object()));
@ -1728,7 +1727,6 @@ public abstract class AbstractByteBufTest {
assertThat(lastIndex.get(), is(CAPACITY / 4));
}
@Ignore
@Test
public void testInternalNioBuffer() {
testInternalNioBuffer(128);
@ -1796,7 +1794,7 @@ public abstract class AbstractByteBufTest {
return;
}
}
Assert.assertArrayEquals(bytes, channel.writtenBytes());
assertArrayEquals(bytes, channel.writtenBytes());
latch.countDown();
}
try {
@ -1850,7 +1848,7 @@ public abstract class AbstractByteBufTest {
return;
}
}
Assert.assertArrayEquals(bytes, out.toByteArray());
assertArrayEquals(bytes, out.toByteArray());
latch.countDown();
}
try {
@ -1899,11 +1897,11 @@ public abstract class AbstractByteBufTest {
byte[] array = new byte[8];
buf.readBytes(array);
Assert.assertArrayEquals(bytes, array);
assertArrayEquals(bytes, array);
Arrays.fill(array, (byte) 0);
buf.getBytes(0, array);
Assert.assertArrayEquals(bytes, array);
assertArrayEquals(bytes, array);
latch.countDown();
}
@ -1929,6 +1927,7 @@ public abstract class AbstractByteBufTest {
}
@Test
@SuppressWarnings("ForLoopThatDoesntUseLoopVariable")
public void testNioBufferExposeOnlyRegion() {
final ByteBuf buffer = releaseLater(newBuffer(8));
byte[] data = new byte[8];

View File

@ -71,8 +71,7 @@ public abstract class AbstractCompositeByteBufTest extends AbstractByteBufTest {
buffers.add(EMPTY_BUFFER);
}
buffer = Unpooled.wrappedBuffer(
Integer.MAX_VALUE, buffers.toArray(new ByteBuf[buffers.size()])).order(order);
buffer = wrappedBuffer(Integer.MAX_VALUE, buffers.toArray(new ByteBuf[buffers.size()])).order(order);
// Truncate to the requested capacity.
buffer.capacity(length);
@ -802,7 +801,7 @@ public abstract class AbstractCompositeByteBufTest extends AbstractByteBufTest {
CompositeByteBuf cbuf = releaseLater(compositeBuffer());
int len = 8 * 4;
for (int i = 0; i < len; i += 4) {
ByteBuf buf = Unpooled.buffer().writeInt(i);
ByteBuf buf = buffer().writeInt(i);
cbuf.capacity(cbuf.writerIndex()).addComponent(buf).writerIndex(i + 4);
}
cbuf.writeByte(1);

View File

@ -15,7 +15,6 @@
*/
package io.netty.buffer;
import org.junit.Ignore;
import org.junit.Test;
import static org.junit.Assert.*;
@ -44,14 +43,6 @@ public class DuplicateByteBufTest extends AbstractByteBufTest {
new DuplicatedByteBuf(null);
}
@Ignore
@Test
// Test which shows bug
// https://github.com/netty/netty/issues/1802
public void testInternalNioBuffer() {
super.testInternalNioBuffer();
}
// See https://github.com/netty/netty/issues/1800
@Test
public void testIncreaseCapacityWrapped() {

View File

@ -46,15 +46,15 @@ public class ReadOnlyByteBufTest {
@Test
public void testUnwrap() {
ByteBuf buf = buffer(1);
assertSame(buf, Unpooled.unmodifiableBuffer(buf).unwrap());
assertSame(buf, unmodifiableBuffer(buf).unwrap());
}
@Test
public void shouldHaveSameByteOrder() {
ByteBuf buf = buffer(1);
assertSame(BIG_ENDIAN, Unpooled.unmodifiableBuffer(buf).order());
assertSame(BIG_ENDIAN, unmodifiableBuffer(buf).order());
buf = buf.order(LITTLE_ENDIAN);
assertSame(LITTLE_ENDIAN, Unpooled.unmodifiableBuffer(buf).order());
assertSame(LITTLE_ENDIAN, unmodifiableBuffer(buf).order());
}
@Test

View File

@ -445,8 +445,8 @@ public class UnpooledTest {
assertEquals(4, buffer.readInt());
assertFalse(buffer.isReadable());
assertEquals(0, Unpooled.copyInt(null).capacity());
assertEquals(0, Unpooled.copyInt(EMPTY_INTS).capacity());
assertEquals(0, copyInt(null).capacity());
assertEquals(0, copyInt(EMPTY_INTS).capacity());
}
@Test
@ -465,8 +465,8 @@ public class UnpooledTest {
assertEquals(4, buffer.readShort());
assertFalse(buffer.isReadable());
assertEquals(0, Unpooled.copyShort((short[]) null).capacity());
assertEquals(0, Unpooled.copyShort(EMPTY_SHORTS).capacity());
assertEquals(0, copyShort((short[]) null).capacity());
assertEquals(0, copyShort(EMPTY_SHORTS).capacity());
}
@Test
@ -477,8 +477,8 @@ public class UnpooledTest {
assertEquals(4, buffer.readShort());
assertFalse(buffer.isReadable());
assertEquals(0, Unpooled.copyShort((int[]) null).capacity());
assertEquals(0, Unpooled.copyShort(EMPTY_INTS).capacity());
assertEquals(0, copyShort((int[]) null).capacity());
assertEquals(0, copyShort(EMPTY_INTS).capacity());
}
@Test
@ -497,8 +497,8 @@ public class UnpooledTest {
assertEquals(4, buffer.readMedium());
assertFalse(buffer.isReadable());
assertEquals(0, Unpooled.copyMedium(null).capacity());
assertEquals(0, Unpooled.copyMedium(EMPTY_INTS).capacity());
assertEquals(0, copyMedium(null).capacity());
assertEquals(0, copyMedium(EMPTY_INTS).capacity());
}
@Test
@ -517,8 +517,8 @@ public class UnpooledTest {
assertEquals(4, buffer.readLong());
assertFalse(buffer.isReadable());
assertEquals(0, Unpooled.copyLong(null).capacity());
assertEquals(0, Unpooled.copyLong(EMPTY_LONGS).capacity());
assertEquals(0, copyLong(null).capacity());
assertEquals(0, copyLong(EMPTY_LONGS).capacity());
}
@Test
@ -537,8 +537,8 @@ public class UnpooledTest {
assertEquals(4, buffer.readFloat(), 0.01);
assertFalse(buffer.isReadable());
assertEquals(0, Unpooled.copyFloat(null).capacity());
assertEquals(0, Unpooled.copyFloat(EMPTY_FLOATS).capacity());
assertEquals(0, copyFloat(null).capacity());
assertEquals(0, copyFloat(EMPTY_FLOATS).capacity());
}
@Test
@ -557,8 +557,8 @@ public class UnpooledTest {
assertEquals(4, buffer.readDouble(), 0.01);
assertFalse(buffer.isReadable());
assertEquals(0, Unpooled.copyDouble(null).capacity());
assertEquals(0, Unpooled.copyDouble(EMPTY_DOUBLES).capacity());
assertEquals(0, copyDouble(null).capacity());
assertEquals(0, copyDouble(EMPTY_DOUBLES).capacity());
}
@Test
@ -569,8 +569,8 @@ public class UnpooledTest {
assertFalse(buffer.readBoolean());
assertFalse(buffer.isReadable());
assertEquals(0, Unpooled.copyBoolean(null).capacity());
assertEquals(0, Unpooled.copyBoolean(EMPTY_BOOLEANS).capacity());
assertEquals(0, copyBoolean(null).capacity());
assertEquals(0, copyBoolean(EMPTY_BOOLEANS).capacity());
}
@Test

View File

@ -123,6 +123,7 @@ public class HttpContentCompressor extends HttpContentEncoder {
wrapper, compressionLevel, windowBits, memLevel)));
}
@SuppressWarnings("FloatingPointEquality")
protected ZlibWrapper determineWrapper(String acceptEncoding) {
float starQ = -1.0f;
float gzipQ = -1.0f;

View File

@ -35,7 +35,7 @@ import static io.netty.handler.codec.http.HttpConstants.*;
*/
public abstract class HttpHeaders implements Iterable<Map.Entry<String, String>> {
private static final byte[] HEADER_SEPERATOR = { HttpConstants.COLON, HttpConstants.SP };
private static final byte[] HEADER_SEPERATOR = { COLON, SP };
private static final byte[] CRLF = { CR, LF };
private static final CharSequence CONTENT_LENGTH_ENTITY = newEntity(Names.CONTENT_LENGTH);
private static final CharSequence CONNECTION_ENTITY = newEntity(Names.CONNECTION);
@ -785,7 +785,7 @@ public abstract class HttpHeaders implements Iterable<Map.Entry<String, String>>
try {
return Integer.parseInt(value);
} catch (NumberFormatException e) {
} catch (NumberFormatException ignored) {
return defaultValue;
}
}
@ -882,7 +882,7 @@ public abstract class HttpHeaders implements Iterable<Map.Entry<String, String>>
try {
return HttpHeaderDateFormat.get().parse(value);
} catch (ParseException e) {
} catch (ParseException ignored) {
return defaultValue;
}
}
@ -985,7 +985,7 @@ public abstract class HttpHeaders implements Iterable<Map.Entry<String, String>>
if (contentLength != null) {
try {
return Long.parseLong(contentLength);
} catch (NumberFormatException e) {
} catch (NumberFormatException ignored) {
return defaultValue;
}
}
@ -1361,6 +1361,7 @@ public abstract class HttpHeaders implements Iterable<Map.Entry<String, String>>
}
}
@SuppressWarnings("deprecation")
static void encode(CharSequence key, CharSequence value, ByteBuf buf) {
encodeAscii(key, buf);
buf.writeBytes(HEADER_SEPERATOR);

View File

@ -23,6 +23,7 @@ import io.netty.channel.ChannelPipeline;
import io.netty.handler.codec.DecoderResult;
import io.netty.handler.codec.ReplayingDecoder;
import io.netty.handler.codec.TooLongFrameException;
import io.netty.handler.codec.http.HttpObjectDecoder.State;
import io.netty.util.internal.AppendableCharSequence;
import java.util.List;
@ -100,7 +101,7 @@ import static io.netty.buffer.ByteBufUtil.*;
* To implement the decoder of such a derived protocol, extend this class and
* implement all abstract methods properly.
*/
public abstract class HttpObjectDecoder extends ReplayingDecoder<HttpObjectDecoder.State> {
public abstract class HttpObjectDecoder extends ReplayingDecoder<State> {
private final int maxInitialLineLength;
private final int maxHeaderSize;

View File

@ -266,7 +266,7 @@ public final class CorsConfig {
* @return {@link Builder} to support method chaining.
*/
public static Builder withOrigin(final String origin) {
if (origin.equals("*")) {
if ("*".equals(origin)) {
return new Builder();
}
return new Builder(origin);

View File

@ -18,7 +18,7 @@ package io.netty.handler.codec.http.multipart;
import java.io.Serializable;
import java.util.Comparator;
final class CaseIgnoringComparator implements Comparator<String>, Serializable {
final class CaseIgnoringComparator implements Comparator<CharSequence>, Serializable {
private static final long serialVersionUID = 4582133183775373862L;
@ -28,8 +28,26 @@ final class CaseIgnoringComparator implements Comparator<String>, Serializable {
}
@Override
public int compare(String o1, String o2) {
return o1.compareToIgnoreCase(o2);
public int compare(CharSequence o1, CharSequence o2) {
int o1Length = o1.length();
int o2Length = o2.length();
int min = Math.min(o1Length, o2Length);
for (int i = 0; i < min; i++) {
char c1 = o1.charAt(i);
char c2 = o2.charAt(i);
if (c1 != c2) {
c1 = Character.toUpperCase(c1);
c2 = Character.toUpperCase(c2);
if (c1 != c2) {
c1 = Character.toLowerCase(c1);
c2 = Character.toLowerCase(c2);
if (c1 != c2) {
return c1 - c2;
}
}
}
}
return o1Length - o2Length;
}
private Object readResolve() {

View File

@ -21,8 +21,10 @@ import io.netty.util.internal.PlatformDependent;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
/**
* Default factory giving Attribute and FileUpload according to constructor
@ -176,15 +178,18 @@ public class DefaultHttpDataFactory implements HttpDataFactory {
@Override
public void cleanAllHttpDatas() {
for (HttpRequest request : requestFileDeleteMap.keySet()) {
List<HttpData> fileToDelete = requestFileDeleteMap.get(request);
Iterator<Entry<HttpRequest, List<HttpData>>> i = requestFileDeleteMap.entrySet().iterator();
while (i.hasNext()) {
Entry<HttpRequest, List<HttpData>> e = i.next();
i.remove();
List<HttpData> fileToDelete = e.getValue();
if (fileToDelete != null) {
for (HttpData data: fileToDelete) {
for (HttpData data : fileToDelete) {
data.delete();
}
fileToDelete.clear();
}
requestFileDeleteMap.remove(request);
}
}
}

View File

@ -22,7 +22,6 @@ import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.ChannelPipeline;
import io.netty.handler.codec.http.DefaultFullHttpResponse;
import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpRequest;
import io.netty.handler.codec.http.HttpResponse;
import io.netty.handler.ssl.SslHandler;
@ -101,7 +100,7 @@ class WebSocketServerProtocolHandshakeHandler
// SSL in use so use Secure WebSockets
protocol = "wss";
}
return protocol + "://" + req.headers().get(HttpHeaders.Names.HOST) + path;
return protocol + "://" + req.headers().get(Names.HOST) + path;
}
}

View File

@ -17,6 +17,7 @@ package io.netty.handler.codec.rtsp;
import io.netty.buffer.ByteBuf;
import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpRequest;
import io.netty.util.CharsetUtil;
@ -36,9 +37,9 @@ public class RtspRequestEncoder extends RtspObjectEncoder<HttpRequest> {
}
@Override
protected void encodeInitialLine(ByteBuf buf, HttpRequest request)
throws Exception {
encodeAscii(request.getMethod().toString(), buf);
@SuppressWarnings("deprecation")
protected void encodeInitialLine(ByteBuf buf, HttpRequest request) throws Exception {
HttpHeaders.encodeAscii(request.getMethod().toString(), buf);
buf.writeByte(SP);
buf.writeBytes(request.getUri().getBytes(CharsetUtil.UTF_8));
buf.writeByte(SP);

View File

@ -17,6 +17,7 @@ package io.netty.handler.codec.rtsp;
import io.netty.buffer.ByteBuf;
import io.netty.handler.codec.http.FullHttpResponse;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpResponse;
import io.netty.util.CharsetUtil;
@ -25,7 +26,6 @@ import static io.netty.handler.codec.http.HttpConstants.*;
/**
* Encodes an RTSP response represented in {@link FullHttpResponse} into
* a {@link ByteBuf}.
*/
public class RtspResponseEncoder extends RtspObjectEncoder<HttpResponse> {
private static final byte[] CRLF = { CR, LF };
@ -36,9 +36,9 @@ public class RtspResponseEncoder extends RtspObjectEncoder<HttpResponse> {
}
@Override
protected void encodeInitialLine(ByteBuf buf, HttpResponse response)
throws Exception {
encodeAscii(response.getProtocolVersion().toString(), buf);
@SuppressWarnings("deprecation")
protected void encodeInitialLine(ByteBuf buf, HttpResponse response) throws Exception {
HttpHeaders.encodeAscii(response.getProtocolVersion().toString(), buf);
buf.writeByte(SP);
buf.writeBytes(String.valueOf(response.getStatus().code()).getBytes(CharsetUtil.US_ASCII));
buf.writeByte(SP);

View File

@ -33,11 +33,11 @@ public class SpdyHeaderBlockRawEncoder extends SpdyHeaderBlockEncoder {
this.version = version.getVersion();
}
private void setLengthField(ByteBuf buffer, int writerIndex, int length) {
private static void setLengthField(ByteBuf buffer, int writerIndex, int length) {
buffer.setInt(writerIndex, length);
}
private void writeLengthField(ByteBuf buffer, int length) {
private static void writeLengthField(ByteBuf buffer, int length) {
buffer.writeInt(length);
}

View File

@ -18,6 +18,7 @@ package io.netty.handler.codec.spdy;
import io.netty.channel.ChannelPromise;
import io.netty.util.internal.PlatformDependent;
import java.io.Serializable;
import java.util.Comparator;
import java.util.Map;
import java.util.Queue;
@ -320,7 +321,10 @@ final class SpdySession {
}
}
private final class PriorityComparator implements Comparator<Integer> {
private final class PriorityComparator implements Comparator<Integer>, Serializable {
private static final long serialVersionUID = 1161471649740544848L;
@Override
public int compare(Integer id1, Integer id2) {
StreamState state1 = activeStreams.get(id1);

View File

@ -15,8 +15,6 @@
*/
package io.netty.handler.codec.http;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import io.netty.buffer.ByteBuf;
import io.netty.channel.embedded.EmbeddedChannel;
import io.netty.handler.stream.ChunkedFile;
@ -25,6 +23,7 @@ import io.netty.handler.stream.ChunkedNioFile;
import io.netty.handler.stream.ChunkedNioStream;
import io.netty.handler.stream.ChunkedStream;
import io.netty.handler.stream.ChunkedWriteHandler;
import org.junit.Test;
import java.io.ByteArrayInputStream;
import java.io.File;
@ -32,7 +31,7 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.Channels;
import org.junit.Test;
import static org.junit.Assert.*;
public class HttpChunkedInputTest {
private static final byte[] BYTES = new byte[1024 * 64];
@ -119,6 +118,6 @@ public class HttpChunkedInputTest {
}
assertEquals(BYTES.length * inputs.length, read);
assertTrue("Last chunk must be DefaultLastHttpContent", lastHttpContent == LastHttpContent.EMPTY_LAST_CONTENT);
assertSame("Last chunk must be DefaultLastHttpContent", LastHttpContent.EMPTY_LAST_CONTENT, lastHttpContent);
}
}

View File

@ -15,11 +15,12 @@
*/
package io.netty.handler.codec.http;
import org.junit.Test;
import java.text.ParseException;
import java.util.Date;
import org.junit.Assert;
import org.junit.Test;
import static org.junit.Assert.*;
public class HttpHeaderDateFormatTest {
/**
@ -35,28 +36,24 @@ public class HttpHeaderDateFormatTest {
HttpHeaderDateFormat format = HttpHeaderDateFormat.get();
final Date parsedDateWithSingleDigitDay = format.parse("Sun, 6 Nov 1994 08:49:37 GMT");
Assert.assertNotNull(parsedDateWithSingleDigitDay);
Assert.assertEquals(DATE, parsedDateWithSingleDigitDay);
assertNotNull(parsedDateWithSingleDigitDay);
assertEquals(DATE, parsedDateWithSingleDigitDay);
final Date parsedDateWithDoubleDigitDay = format.parse("Sun, 06 Nov 1994 08:49:37 GMT");
Assert.assertNotNull(parsedDateWithDoubleDigitDay);
Assert.assertEquals(DATE, parsedDateWithDoubleDigitDay);
assertNotNull(parsedDateWithDoubleDigitDay);
assertEquals(DATE, parsedDateWithDoubleDigitDay);
final Date parsedDateWithDashSeparatorSingleDigitDay = format.parse("Sunday, 06-Nov-94 08:49:37 GMT");
Assert.assertNotNull(parsedDateWithDashSeparatorSingleDigitDay);
Assert.assertEquals(DATE, parsedDateWithDashSeparatorSingleDigitDay);
assertNotNull(parsedDateWithDashSeparatorSingleDigitDay);
assertEquals(DATE, parsedDateWithDashSeparatorSingleDigitDay);
final Date parsedDateWithSingleDoubleDigitDay = format.parse("Sunday, 6-Nov-94 08:49:37 GMT");
Assert.assertNotNull(parsedDateWithSingleDoubleDigitDay);
Assert.assertEquals(DATE, parsedDateWithSingleDoubleDigitDay);
assertNotNull(parsedDateWithSingleDoubleDigitDay);
assertEquals(DATE, parsedDateWithSingleDoubleDigitDay);
final Date parsedDateWithoutGMT = format.parse("Sun Nov 6 08:49:37 1994");
Assert.assertNotNull(parsedDateWithoutGMT);
Assert.assertEquals(DATE, parsedDateWithoutGMT);
}
private Date parseDate(HttpHeaderDateFormat dateFormat, String dateStr) throws ParseException {
return dateFormat.parse(dateStr);
assertNotNull(parsedDateWithoutGMT);
assertEquals(DATE, parsedDateWithoutGMT);
}
@Test
@ -64,7 +61,7 @@ public class HttpHeaderDateFormatTest {
HttpHeaderDateFormat format = HttpHeaderDateFormat.get();
final String formatted = format.format(DATE);
Assert.assertNotNull(formatted);
Assert.assertEquals("Sun, 06 Nov 1994 08:49:37 GMT", formatted);
assertNotNull(formatted);
assertEquals("Sun, 06 Nov 1994 08:49:37 GMT", formatted);
}
}

View File

@ -194,7 +194,7 @@ public class HttpObjectAggregatorTest {
ch.writeInbound(Unpooled.copiedBuffer("GET / HTTP/1.0 with extra\r\n", CharsetUtil.UTF_8));
Object inbound = ch.readInbound();
assertThat(inbound, is(instanceOf(FullHttpRequest.class)));
assertTrue(((FullHttpRequest) inbound).getDecoderResult().isFailure());
assertTrue(((HttpObject) inbound).getDecoderResult().isFailure());
assertNull(ch.readInbound());
ch.finish();
}
@ -205,7 +205,7 @@ public class HttpObjectAggregatorTest {
ch.writeInbound(Unpooled.copiedBuffer("HTTP/1.0 BAD_CODE Bad Server\r\n", CharsetUtil.UTF_8));
Object inbound = ch.readInbound();
assertThat(inbound, is(instanceOf(FullHttpResponse.class)));
assertTrue(((FullHttpResponse) inbound).getDecoderResult().isFailure());
assertTrue(((HttpObject) inbound).getDecoderResult().isFailure());
assertNull(ch.readInbound());
ch.finish();
}

View File

@ -135,7 +135,6 @@ public class HttpRequestDecoderTest {
}
// if header is done it should produce a HttpRequest
boolean headerDone = a + amount == headerLength;
channel.writeInbound(Unpooled.wrappedBuffer(content, a, amount));
a += amount;
}

View File

@ -47,7 +47,7 @@ public class HttpResponseEncoderTest {
buffer.release();
FileRegion region = (FileRegion) channel.readOutbound();
assertSame(region, FILE_REGION);
assertSame(FILE_REGION, region);
region.release();
buffer = (ByteBuf) channel.readOutbound();
assertEquals("\r\n", buffer.toString(CharsetUtil.US_ASCII));

View File

@ -78,7 +78,7 @@ public class CorsHandlerTest {
@Test
public void preflightDeleteRequestWithCustomHeaders() {
final CorsConfig config = CorsConfig.withOrigin("http://localhost:8888")
.allowedRequestMethods(HttpMethod.GET, HttpMethod.DELETE)
.allowedRequestMethods(GET, DELETE)
.build();
final HttpResponse response = preflightRequest(config, "http://localhost:8888", "content-type, xheader1");
assertThat(response.headers().get(ACCESS_CONTROL_ALLOW_ORIGIN), is("http://localhost:8888"));
@ -89,7 +89,7 @@ public class CorsHandlerTest {
@Test
public void preflightGetRequestWithCustomHeaders() {
final CorsConfig config = CorsConfig.withOrigin("http://localhost:8888")
.allowedRequestMethods(HttpMethod.OPTIONS, HttpMethod.GET, HttpMethod.DELETE)
.allowedRequestMethods(OPTIONS, GET, DELETE)
.allowedRequestHeaders("content-type", "xheader1")
.build();
final HttpResponse response = preflightRequest(config, "http://localhost:8888", "content-type, xheader1");

View File

@ -172,7 +172,7 @@ public class SpdySessionHandlerTest {
// a RST_STREAM frame for that Stream-ID
sessionHandler.writeInbound(new DefaultSpdyRstStreamFrame(remoteStreamId, 3));
assertNull(sessionHandler.readOutbound());
remoteStreamId += 2;
//remoteStreamId += 2;
// Check if session handler honors UNIDIRECTIONAL streams
spdySynStreamFrame.setLast(false);

View File

@ -18,6 +18,7 @@ package io.netty.handler.codec.socks;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ReplayingDecoder;
import io.netty.handler.codec.socks.SocksAuthRequestDecoder.State;
import io.netty.util.CharsetUtil;
import java.util.List;
@ -26,7 +27,7 @@ import java.util.List;
* Decodes {@link ByteBuf}s into {@link SocksAuthRequest}.
* Before returning SocksRequest decoder removes itself from pipeline.
*/
public class SocksAuthRequestDecoder extends ReplayingDecoder<SocksAuthRequestDecoder.State> {
public class SocksAuthRequestDecoder extends ReplayingDecoder<State> {
private static final String name = "SOCKS_AUTH_REQUEST_DECODER";
/**

View File

@ -18,6 +18,7 @@ package io.netty.handler.codec.socks;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ReplayingDecoder;
import io.netty.handler.codec.socks.SocksAuthResponseDecoder.State;
import java.util.List;
@ -25,7 +26,7 @@ import java.util.List;
* Decodes {@link ByteBuf}s into {@link SocksAuthResponse}.
* Before returning SocksResponse decoder removes itself from pipeline.
*/
public class SocksAuthResponseDecoder extends ReplayingDecoder<SocksAuthResponseDecoder.State> {
public class SocksAuthResponseDecoder extends ReplayingDecoder<State> {
private static final String name = "SOCKS_AUTH_RESPONSE_DECODER";
/**

View File

@ -18,6 +18,7 @@ package io.netty.handler.codec.socks;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ReplayingDecoder;
import io.netty.handler.codec.socks.SocksCmdRequestDecoder.State;
import io.netty.util.CharsetUtil;
import java.util.List;
@ -26,7 +27,7 @@ import java.util.List;
* Decodes {@link ByteBuf}s into {@link SocksCmdRequest}.
* Before returning SocksRequest decoder removes itself from pipeline.
*/
public class SocksCmdRequestDecoder extends ReplayingDecoder<SocksCmdRequestDecoder.State> {
public class SocksCmdRequestDecoder extends ReplayingDecoder<State> {
private static final String name = "SOCKS_CMD_REQUEST_DECODER";
/**
@ -41,6 +42,7 @@ public class SocksCmdRequestDecoder extends ReplayingDecoder<SocksCmdRequestDeco
private int fieldLength;
private SocksCmdType cmdType;
private SocksAddressType addressType;
@SuppressWarnings("UnusedDeclaration")
private byte reserved;
private String host;
private int port;

View File

@ -18,6 +18,7 @@ package io.netty.handler.codec.socks;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ReplayingDecoder;
import io.netty.handler.codec.socks.SocksCmdResponseDecoder.State;
import io.netty.util.CharsetUtil;
import java.util.List;
@ -26,7 +27,7 @@ import java.util.List;
* Decodes {@link ByteBuf}s into {@link SocksCmdResponse}.
* Before returning SocksResponse decoder removes itself from pipeline.
*/
public class SocksCmdResponseDecoder extends ReplayingDecoder<SocksCmdResponseDecoder.State> {
public class SocksCmdResponseDecoder extends ReplayingDecoder<State> {
private static final String name = "SOCKS_CMD_RESPONSE_DECODER";
/**

View File

@ -18,6 +18,7 @@ package io.netty.handler.codec.socks;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ReplayingDecoder;
import io.netty.handler.codec.socks.SocksInitRequestDecoder.State;
import java.util.ArrayList;
import java.util.List;
@ -26,7 +27,7 @@ import java.util.List;
* Decodes {@link ByteBuf}s into {@link SocksInitRequest}.
* Before returning SocksRequest decoder removes itself from pipeline.
*/
public class SocksInitRequestDecoder extends ReplayingDecoder<SocksInitRequestDecoder.State> {
public class SocksInitRequestDecoder extends ReplayingDecoder<State> {
private static final String name = "SOCKS_INIT_REQUEST_DECODER";
/**

View File

@ -18,6 +18,7 @@ package io.netty.handler.codec.socks;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ReplayingDecoder;
import io.netty.handler.codec.socks.SocksInitResponseDecoder.State;
import java.util.List;
@ -25,7 +26,7 @@ import java.util.List;
* Decodes {@link ByteBuf}s into {@link SocksInitResponse}.
* Before returning SocksResponse decoder removes itself from pipeline.
*/
public class SocksInitResponseDecoder extends ReplayingDecoder<SocksInitResponseDecoder.State> {
public class SocksInitResponseDecoder extends ReplayingDecoder<State> {
private static final String name = "SOCKS_INIT_RESPONSE_DECODER";
/**

View File

@ -27,6 +27,7 @@ final class SocksCommonTestUtils {
//NOOP
}
@SuppressWarnings("deprecation")
public static void writeMessageIntoEmbedder(EmbeddedChannel embedder, SocksMessage msg) {
ByteBuf buf = Unpooled.buffer();
msg.encodeAsByteBuf(buf);

View File

@ -286,7 +286,7 @@ public final class Base64 {
(DECODABET[src[srcOffset + 1]] & 0xFF) << 12 |
(DECODABET[src[srcOffset + 2]] & 0xFF) << 6 |
DECODABET[src[srcOffset + 3]] & 0xFF;
} catch (IndexOutOfBoundsException e) {
} catch (IndexOutOfBoundsException ignored) {
throw new IllegalArgumentException("not encoded in Base64");
}

View File

@ -93,7 +93,7 @@ class Crc32c implements Checksum {
0xBE2DA0A5, 0x4C4623A6, 0x5F16D052, 0xAD7D5351,
};
private static final int LONG_MASK = 0xFFFFFFFF;
private static final long LONG_MASK = 0xFFFFFFFFL;
private static final int BYTE_MASK = 0xFF;
private int crc = ~0;
@ -121,6 +121,6 @@ class Crc32c implements Checksum {
}
private static int crc32c(int crc, int b) {
return (crc >>> 8) ^ CRC_TABLE[(crc ^ (b & BYTE_MASK)) & BYTE_MASK];
return crc >>> 8 ^ CRC_TABLE[(crc ^ b & BYTE_MASK) & BYTE_MASK];
}
}

View File

@ -57,7 +57,7 @@ public class Snappy {
written = 0;
}
public void encode(ByteBuf in, ByteBuf out, int length) {
public void encode(final ByteBuf in, final ByteBuf out, final int length) {
// Write the preamble length to the output buffer
for (int i = 0;; i ++) {
int b = length >>> i * 7;
@ -70,15 +70,14 @@ public class Snappy {
}
int inIndex = in.readerIndex();
final int baseIndex = in.readerIndex();
final int maxIndex = length;
final int baseIndex = inIndex;
final short[] table = getHashTable(maxIndex);
final short[] table = getHashTable(length);
final int shift = 32 - (int) Math.floor(Math.log(table.length) / Math.log(2));
int nextEmit = inIndex;
if (maxIndex - inIndex >= MIN_COMPRESSIBLE_BYTES) {
if (length - inIndex >= MIN_COMPRESSIBLE_BYTES) {
int nextHash = hash(in, ++inIndex, shift);
outer: while (true) {
int skip = 32;
@ -92,7 +91,7 @@ public class Snappy {
nextIndex = inIndex + bytesBetweenHashLookups;
// We need at least 4 remaining bytes to read the hash
if (nextIndex > maxIndex - 4) {
if (nextIndex > length - 4) {
break outer;
}
@ -109,14 +108,14 @@ public class Snappy {
int insertTail;
do {
int base = inIndex;
int matched = 4 + findMatchingLength(in, candidate + 4, inIndex + 4, maxIndex);
int matched = 4 + findMatchingLength(in, candidate + 4, inIndex + 4, length);
inIndex += matched;
int offset = base - candidate;
encodeCopy(out, offset, matched);
in.readerIndex(in.readerIndex() + matched);
insertTail = inIndex - 1;
nextEmit = inIndex;
if (inIndex >= maxIndex - 4) {
if (inIndex >= length - 4) {
break outer;
}
@ -134,8 +133,8 @@ public class Snappy {
}
// If there are any remaining characters, write them out as a literal
if (nextEmit < maxIndex) {
encodeLiteral(in, out, maxIndex - nextEmit);
if (nextEmit < length) {
encodeLiteral(in, out, length - nextEmit);
}
}

View File

@ -27,7 +27,7 @@ class ChannelBufferByteInput implements ByteInput {
private final ByteBuf buffer;
public ChannelBufferByteInput(ByteBuf buffer) {
ChannelBufferByteInput(ByteBuf buffer) {
this.buffer = buffer;
}

View File

@ -32,7 +32,7 @@ class ChannelBufferByteOutput implements ByteOutput {
/**
* Create a new instance which use the given {@link ByteBuf}
*/
public ChannelBufferByteOutput(ByteBuf buffer) {
ChannelBufferByteOutput(ByteBuf buffer) {
this.buffer = buffer;
}

View File

@ -20,13 +20,12 @@ import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ReplayingDecoder;
import io.netty.handler.codec.TooLongFrameException;
import org.jboss.marshalling.ByteInput;
import org.jboss.marshalling.Unmarshaller;
import java.io.ObjectStreamConstants;
import java.util.List;
import org.jboss.marshalling.ByteInput;
import org.jboss.marshalling.Unmarshaller;
/**
* {@link ReplayingDecoder} which use an {@link Unmarshaller} to read the Object out of the {@link ByteBuf}.
*
@ -73,7 +72,7 @@ public class CompatibleMarshallingDecoder extends ReplayingDecoder<Void> {
Object obj = unmarshaller.readObject();
unmarshaller.finish();
out.add(obj);
} catch (LimitingByteInput.TooBigObjectException e) {
} catch (LimitingByteInput.TooBigObjectException ignored) {
discardingTooLongFrame = true;
throw new TooLongFrameException();
} finally {

View File

@ -32,7 +32,7 @@ class LimitingByteInput implements ByteInput {
private final long limit;
private long read;
public LimitingByteInput(ByteInput input, long limit) {
LimitingByteInput(ByteInput input, long limit) {
if (limit <= 0) {
throw new IllegalArgumentException("The limit MUST be > 0");
}

View File

@ -27,7 +27,7 @@ class ClassLoaderClassResolver implements ClassResolver {
public Class<?> resolve(String className) throws ClassNotFoundException {
try {
return classLoader.loadClass(className);
} catch (ClassNotFoundException e) {
} catch (ClassNotFoundException ignored) {
return Class.forName(className, false, classLoader);
}
}

View File

@ -65,7 +65,7 @@ class CompactObjectInputStream extends ObjectInputStream {
Class<?> clazz;
try {
clazz = classResolver.resolve(desc.getName());
} catch (ClassNotFoundException ex) {
} catch (ClassNotFoundException ignored) {
clazz = super.resolveClass(desc);
}

View File

@ -21,7 +21,7 @@ import java.util.Map;
final class SoftReferenceMap<K, V> extends ReferenceMap<K, V> {
public SoftReferenceMap(Map<K, Reference<V>> delegate) {
SoftReferenceMap(Map<K, Reference<V>> delegate) {
super(delegate);
}

View File

@ -21,7 +21,7 @@ import java.util.Map;
final class WeakReferenceMap<K, V> extends ReferenceMap<K, V> {
public WeakReferenceMap(Map<K, Reference<V>> delegate) {
WeakReferenceMap(Map<K, Reference<V>> delegate) {
super(delegate);
}

View File

@ -26,9 +26,6 @@ import static io.netty.buffer.Unpooled.*;
import static org.hamcrest.core.Is.*;
import static org.junit.Assert.*;
/**
*/
@SuppressWarnings("ZeroLengthArrayAllocation")
public class ByteArrayDecoderTest {
private EmbeddedChannel ch;

View File

@ -31,6 +31,7 @@ public class JdkZlibTest extends ZlibTest {
}
@Test(expected = DecompressionException.class)
@Override
public void testZLIB_OR_NONE3() throws Exception {
super.testZLIB_OR_NONE3();
}

View File

@ -30,6 +30,7 @@ public class ZlibCrossTest2 extends ZlibTest {
}
@Test(expected = DecompressionException.class)
@Override
public void testZLIB_OR_NONE3() throws Exception {
super.testZLIB_OR_NONE3();
}

View File

@ -35,7 +35,6 @@ public abstract class AbstractReferenceCounted implements ReferenceCounted {
refCntUpdater = updater;
}
@SuppressWarnings("FieldMayBeFinal")
private volatile int refCnt = 1;
@Override

View File

@ -48,7 +48,7 @@ public class DefaultAttributeMap implements AttributeMap {
@SuppressWarnings("UnusedDeclaration")
private volatile AtomicReferenceArray<DefaultAttribute<?>> attributes;
@SuppressWarnings({ "unchecked", "rawtypes" })
@SuppressWarnings("unchecked")
@Override
public <T> Attribute<T> attr(AttributeKey<T> key) {
if (key == null) {

View File

@ -222,7 +222,6 @@ public class HashedWheelTimer implements Timer {
leak = leakDetector.open(this);
}
@SuppressWarnings("unchecked")
private static HashedWheelBucket[] createWheel(int ticksPerWheel) {
if (ticksPerWheel <= 0) {
throw new IllegalArgumentException(
@ -306,7 +305,7 @@ public class HashedWheelTimer implements Timer {
workerThread.interrupt();
try {
workerThread.join(100);
} catch (InterruptedException e) {
} catch (InterruptedException ignored) {
interrupted = true;
}
}
@ -397,8 +396,7 @@ public class HashedWheelTimer implements Timer {
continue;
}
long calculated = timeout.deadline / tickDuration;
long remainingRounds = (calculated - tick) / wheel.length;
timeout.remainingRounds = remainingRounds;
timeout.remainingRounds = (calculated - tick) / wheel.length;
final long ticks = Math.max(calculated, tick); // Ensure we don't schedule for past.
int stopIndex = (int) (ticks & mask);
@ -439,7 +437,7 @@ public class HashedWheelTimer implements Timer {
try {
Thread.sleep(sleepTimeMs);
} catch (InterruptedException e) {
} catch (InterruptedException ignored) {
if (WORKER_STATE_UPDATER.get(HashedWheelTimer.this) == WORKER_STATE_SHUTDOWN) {
return Long.MIN_VALUE;
}

View File

@ -160,7 +160,7 @@ public abstract class Recycler<T> {
private final WeakReference<Thread> owner;
private final int id = ID_GENERATOR.getAndIncrement();
public WeakOrderQueue(Stack<?> stack, Thread thread) {
WeakOrderQueue(Stack<?> stack, Thread thread) {
head = tail = new Link();
owner = new WeakReference<Thread>(thread);
synchronized (stack) {
@ -190,6 +190,7 @@ public abstract class Recycler<T> {
}
// transfer as many items as we can from this queue to the stack, returning true if any were transferred
@SuppressWarnings("rawtypes")
boolean transfer(Stack<?> to) {
Link head = this.head;

View File

@ -132,7 +132,7 @@ public final class Version {
private static long parseIso8601(String value) {
try {
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z").parse(value).getTime();
} catch (ParseException e) {
} catch (ParseException ignored) {
return 0;
}
}

View File

@ -47,7 +47,7 @@ public class IntObjectHashMap<V> implements IntObjectMap<V>, Iterable<IntObjectM
/** The maximum number of elements allowed without allocating more space. */
private int maxSize;
/** The load factor for the map. Used to calculate {@link maxSize}. */
/** The load factor for the map. Used to calculate {@link #maxSize}. */
private final float loadFactor;
private byte[] states;
@ -74,10 +74,13 @@ public class IntObjectHashMap<V> implements IntObjectMap<V>, Iterable<IntObjectM
this.loadFactor = loadFactor;
// Adjust the initial capacity if necessary.
initialCapacity = adjustCapacity(initialCapacity);
// Allocate the arrays.
states = new byte[initialCapacity];
keys = new int[initialCapacity];
@SuppressWarnings("unchecked")
@SuppressWarnings({ "unchecked", "SuspiciousArrayCast" })
V[] temp = (V[]) new Object[initialCapacity];
values = temp;
@ -99,7 +102,7 @@ public class IntObjectHashMap<V> implements IntObjectMap<V>, Iterable<IntObjectM
int hash = hash(key);
int capacity = capacity();
int index = hash % capacity;
int increment = 1 + (hash % (capacity - 2));
int increment = 1 + hash % (capacity - 2);
final int startIndex = index;
int firstRemovedIndex = -1;
do {
@ -212,7 +215,7 @@ public class IntObjectHashMap<V> implements IntObjectMap<V>, Iterable<IntObjectM
int i = -1;
while ((i = nextEntryIndex(i + 1)) >= 0) {
V next = values[i];
if (value == next || (value != null && value.equals(next))) {
if (value == next || value != null && value.equals(next)) {
return true;
}
}
@ -265,7 +268,7 @@ public class IntObjectHashMap<V> implements IntObjectMap<V>, Iterable<IntObjectM
private int indexOf(int key) {
int hash = hash(key);
int capacity = capacity();
int increment = 1 + (hash % (capacity - 2));
int increment = 1 + hash % (capacity - 2);
int index = hash % capacity;
int startIndex = index;
do {
@ -305,7 +308,7 @@ public class IntObjectHashMap<V> implements IntObjectMap<V>, Iterable<IntObjectM
/**
* Creates a hash value for the given key.
*/
private int hash(int key) {
private static int hash(int key) {
// Just make sure the integer is positive.
return key & Integer.MAX_VALUE;
}
@ -336,8 +339,7 @@ public class IntObjectHashMap<V> implements IntObjectMap<V>, Iterable<IntObjectM
if (size > maxSize) {
// Need to grow the arrays.
// TODO: consider using the next prime greater than capacity * 2.
rehash(capacity() * 2);
rehash(adjustCapacity(capacity() * 2));
} else if (available == 0) {
// Open addressing requires that we have at least 1 slot available. Need to refresh
// the arrays to clear any removed elements.
@ -346,7 +348,15 @@ public class IntObjectHashMap<V> implements IntObjectMap<V>, Iterable<IntObjectM
}
/**
* Marks the entry at the given index position as {@link REMOVED} and sets the value to
* Adjusts the given capacity value to ensure that it's odd. Even capacities can break probing.
* TODO: would be better to ensure it's prime as well.
*/
private static int adjustCapacity(int capacity) {
return capacity | 1;
}
/**
* Marks the entry at the given index position as {@link #REMOVED} and sets the value to
* {@code null}.
* <p>
* TODO: consider performing re-compaction.
@ -385,7 +395,7 @@ public class IntObjectHashMap<V> implements IntObjectMap<V>, Iterable<IntObjectM
// New states array is automatically initialized to AVAILABLE (i.e. 0 == AVAILABLE).
states = new byte[newCapacity];
keys = new int[newCapacity];
@SuppressWarnings("unchecked")
@SuppressWarnings({ "unchecked", "SuspiciousArrayCast" })
V[] temp = (V[]) new Object[newCapacity];
values = temp;

View File

@ -24,7 +24,7 @@ final class DefaultFutureListeners {
private int progressiveSize; // the number of progressive listeners
@SuppressWarnings("unchecked")
public DefaultFutureListeners(
DefaultFutureListeners(
GenericFutureListener<? extends Future<?>> first, GenericFutureListener<? extends Future<?>> second) {
listeners = new GenericFutureListener[2];
listeners[0] = first;

View File

@ -147,7 +147,6 @@ public class DefaultPromise<V> extends AbstractFuture<V> implements Promise<V> {
if (listeners instanceof DefaultFutureListeners) {
((DefaultFutureListeners) listeners).add(listener);
} else {
@SuppressWarnings("unchecked")
final GenericFutureListener<? extends Future<V>> firstListener =
(GenericFutureListener<? extends Future<V>>) listeners;
listeners = new DefaultFutureListeners(firstListener, listener);
@ -559,7 +558,6 @@ public class DefaultPromise<V> extends AbstractFuture<V> implements Promise<V> {
if (listeners instanceof DefaultFutureListeners) {
notifyListeners0(this, (DefaultFutureListeners) listeners);
} else {
@SuppressWarnings("unchecked")
final GenericFutureListener<? extends Future<V>> l =
(GenericFutureListener<? extends Future<V>>) listeners;
notifyListener0(this, l);
@ -582,7 +580,6 @@ public class DefaultPromise<V> extends AbstractFuture<V> implements Promise<V> {
}
});
} else {
@SuppressWarnings("unchecked")
final GenericFutureListener<? extends Future<V>> l =
(GenericFutureListener<? extends Future<V>>) listeners;
execute(executor, new Runnable() {
@ -729,7 +726,7 @@ public class DefaultPromise<V> extends AbstractFuture<V> implements Promise<V> {
}
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@SuppressWarnings("unchecked")
void notifyProgressiveListeners(final long progress, final long total) {
final Object listeners = progressiveListeners();
if (listeners == null) {
@ -794,7 +791,7 @@ public class DefaultPromise<V> extends AbstractFuture<V> implements Promise<V> {
private static final class CauseHolder {
final Throwable cause;
private CauseHolder(Throwable cause) {
CauseHolder(Throwable cause) {
this.cause = cause;
}
}

View File

@ -18,5 +18,6 @@ package io.netty.util.concurrent;
/**
* The result of an scheduled asynchronous operation.
*/
@SuppressWarnings("ClassNameSameAsAncestorName")
public interface ScheduledFuture<V> extends Future<V>, java.util.concurrent.ScheduledFuture<V> {
}

View File

@ -29,6 +29,7 @@ public final class EmptyArrays {
public static final short[] EMPTY_SHORTS = new short[0];
public static final long[] EMPTY_LONGS = new long[0];
public static final Object[] EMPTY_OBJECTS = new Object[0];
public static final Class<?>[] EMPTY_CLASSES = new Class[0];
public static final String[] EMPTY_STRINGS = new String[0];
public static final StackTraceElement[] EMPTY_STACK_TRACE = new StackTraceElement[0];
public static final ByteBuffer[] EMPTY_BYTE_BUFFERS = new ByteBuffer[0];

View File

@ -87,8 +87,7 @@ final class PlatformDependent0 {
// http://www.mail-archive.com/jdk6-dev@openjdk.java.net/msg00698.html
try {
unsafe.getClass().getDeclaredMethod(
"copyMemory",
new Class[] { Object.class, long.class, Object.class, long.class, long.class });
"copyMemory", Object.class, long.class, Object.class, long.class, long.class);
logger.debug("sun.misc.Unsafe.copyMemory: available");
} catch (NoSuchMethodError t) {

View File

@ -29,12 +29,12 @@ import java.util.regex.Pattern;
*/
public final class SystemPropertyUtil {
@SuppressWarnings("all")
private static boolean initializedLogger;
private static final InternalLogger logger;
private static boolean loggedException;
static {
initializedLogger = false;
logger = InternalLoggerFactory.getInstance(SystemPropertyUtil.class);
initializedLogger = true;
}

View File

@ -31,15 +31,15 @@ package io.netty.util.internal.logging;
* as possible and shouldn't be called more than once.
*/
public abstract class InternalLoggerFactory {
private static volatile InternalLoggerFactory defaultFactory;
private static volatile InternalLoggerFactory defaultFactory =
newDefaultFactory(InternalLoggerFactory.class.getName());
static {
final String name = InternalLoggerFactory.class.getName();
@SuppressWarnings("UnusedCatchParameter")
private static InternalLoggerFactory newDefaultFactory(String name) {
InternalLoggerFactory f;
try {
f = new Slf4JLoggerFactory(true);
f.newInstance(name).debug("Using SLF4J as the default logging framework");
defaultFactory = f;
} catch (Throwable t1) {
try {
f = new Log4JLoggerFactory();
@ -49,8 +49,7 @@ public abstract class InternalLoggerFactory {
f.newInstance(name).debug("Using java.util.logging as the default logging framework");
}
}
defaultFactory = f;
return f;
}
/**

View File

@ -72,7 +72,7 @@ class Log4JLogger extends AbstractInternalLogger {
try {
logger.isTraceEnabled();
return true;
} catch (NoSuchMethodError e) {
} catch (NoSuchMethodError ignored) {
return false;
}
}

View File

@ -52,7 +52,7 @@ class Slf4JLogger extends AbstractInternalLogger {
}
@Override
public void trace(String format, Object[] argArray) {
public void trace(String format, Object... argArray) {
logger.trace(format, argArray);
}
@ -82,7 +82,7 @@ class Slf4JLogger extends AbstractInternalLogger {
}
@Override
public void debug(String format, Object[] argArray) {
public void debug(String format, Object... argArray) {
logger.debug(format, argArray);
}
@ -112,7 +112,7 @@ class Slf4JLogger extends AbstractInternalLogger {
}
@Override
public void info(String format, Object[] argArray) {
public void info(String format, Object... argArray) {
logger.info(format, argArray);
}
@ -137,7 +137,7 @@ class Slf4JLogger extends AbstractInternalLogger {
}
@Override
public void warn(String format, Object[] argArray) {
public void warn(String format, Object... argArray) {
logger.warn(format, argArray);
}
@ -172,7 +172,7 @@ class Slf4JLogger extends AbstractInternalLogger {
}
@Override
public void error(String format, Object[] argArray) {
public void error(String format, Object... argArray) {
logger.error(format, argArray);
}

View File

@ -54,7 +54,7 @@ public class Slf4JLoggerFactory extends InternalLoggerFactory {
if (LoggerFactory.getILoggerFactory() instanceof NOPLoggerFactory) {
throw new NoClassDefFoundError(buf.toString());
} else {
err.print(buf.toString());
err.print(buf);
err.flush();
}
} finally {

View File

@ -42,10 +42,10 @@ public class DefaultAttributeMapTest {
assertSame(one, map.attr(key));
one.setIfAbsent("Whoohoo");
assertSame(one.get(), "Whoohoo");
assertSame("Whoohoo", one.get());
one.setIfAbsent("What");
assertNotSame(one.get(), "What");
assertNotSame("What", one.get());
one.remove();
assertNull(one.get());
@ -62,7 +62,7 @@ public class DefaultAttributeMapTest {
assertEquals(one.get(), Integer.valueOf(3653));
one.setIfAbsent(1);
assertNotSame(one.get(), 1);
assertNotSame(1, one.get());
one.remove();
assertNull(one.get());

View File

@ -14,17 +14,13 @@
*/
package io.netty.util.collection;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import org.junit.Before;
import org.junit.Test;
import java.util.HashSet;
import java.util.Set;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Tests for {@link IntObjectHashMap}.
@ -34,7 +30,7 @@ public class IntObjectHashMapTest {
private static class Value {
private final String name;
public Value(String name) {
Value(String name) {
this.name = name;
}
@ -42,7 +38,7 @@ public class IntObjectHashMapTest {
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + (name == null ? 0 : name.hashCode());
return result;
}

View File

@ -61,7 +61,7 @@ public class AppendableCharSequenceTest {
public void testSubSequence() {
AppendableCharSequence master = new AppendableCharSequence(26);
master.append("abcdefghijlkmonpqrstuvwxyz");
assertEquals(master.subSequence(0, 10).toString(), "abcdefghij");
assertEquals("abcdefghij", master.subSequence(0, 10).toString());
}
private static void testSimpleAppend0(AppendableCharSequence seq) {

View File

@ -83,17 +83,14 @@ public class TypeParameterMatcherTest {
public static class TypeQ<I extends BBB> extends TypeZ<AAA, I> { }
@SuppressWarnings("ClassMayBeInterface")
public static class A { }
public static class AA extends A { }
public static class AAA extends AA { }
@SuppressWarnings("ClassMayBeInterface")
public static class B { }
public static class BB extends B { }
public static class BBB extends BB { }
@SuppressWarnings("ClassMayBeInterface")
public static class C { }
public static class CC extends C { }
@ -104,7 +101,6 @@ public class TypeParameterMatcherTest {
assertTrue(m.match(new T()));
}
@SuppressWarnings("ClassMayBeInterface")
private static class T { }
private static class U<E> { E a; }

View File

@ -24,8 +24,6 @@ import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.logging.LogLevel;
import io.netty.handler.logging.LoggingHandler;
import io.netty.handler.ssl.SslContext;
import io.netty.handler.ssl.util.InsecureTrustManagerFactory;

View File

@ -17,7 +17,7 @@ package io.netty.example.http.cors;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.handler.codec.http.DefaultFullHttpResponse;
import io.netty.handler.codec.http.FullHttpResponse;
import io.netty.handler.codec.http.HttpResponseStatus;
@ -27,10 +27,10 @@ import io.netty.handler.codec.http.HttpVersion;
* A simple handler which will simple return a successful Http
* response for any request.
*/
public class OkResponseHandler extends SimpleChannelInboundHandler<Object> {
public class OkResponseHandler extends ChannelInboundHandlerAdapter {
@Override
public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
public void channelRead(ChannelHandlerContext ctx, Object msg) {
final FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
response.headers().set("custom-response-header", "Some value");
ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE);

View File

@ -26,7 +26,7 @@ import io.netty.handler.ssl.SslContext;
import io.netty.handler.ssl.SslProvider;
import io.netty.handler.ssl.util.SelfSignedCertificate;
public class HttpStaticFileServer {
public final class HttpStaticFileServer {
static final boolean SSL = System.getProperty("ssl") != null;
static final int PORT = Integer.parseInt(System.getProperty("port", SSL? "8443" : "8080"));

View File

@ -53,7 +53,6 @@ import java.util.TimeZone;
import java.util.regex.Pattern;
import static io.netty.handler.codec.http.HttpHeaders.Names.*;
import static io.netty.handler.codec.http.HttpHeaders.*;
import static io.netty.handler.codec.http.HttpMethod.*;
import static io.netty.handler.codec.http.HttpResponseStatus.*;
import static io.netty.handler.codec.http.HttpVersion.*;
@ -175,10 +174,10 @@ public class HttpStaticFileServerHandler extends SimpleChannelInboundHandler<Ful
long fileLength = raf.length();
HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK);
setContentLength(response, fileLength);
HttpHeaders.setContentLength(response, fileLength);
setContentTypeHeader(response, file);
setDateAndCacheHeaders(response, file);
if (isKeepAlive(request)) {
if (HttpHeaders.isKeepAlive(request)) {
response.headers().set(CONNECTION, HttpHeaders.Values.KEEP_ALIVE);
}
@ -216,7 +215,7 @@ public class HttpStaticFileServerHandler extends SimpleChannelInboundHandler<Ful
ChannelFuture lastContentFuture = ctx.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT);
// Decide whether to close the connection or not.
if (!isKeepAlive(request)) {
if (!HttpHeaders.isKeepAlive(request)) {
// Close the connection when the whole content is written out.
lastContentFuture.addListener(ChannelFutureListener.CLOSE);
}

View File

@ -21,10 +21,11 @@ import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.handler.codec.http.DefaultFullHttpResponse;
import io.netty.handler.codec.http.FullHttpResponse;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpRequest;
import static io.netty.handler.codec.http.HttpHeaders.Names.*;
import static io.netty.handler.codec.http.HttpHeaders.*;
import static io.netty.handler.codec.http.HttpHeaders.Values;
import static io.netty.handler.codec.http.HttpResponseStatus.*;
import static io.netty.handler.codec.http.HttpVersion.*;
@ -41,10 +42,10 @@ public class HttpHelloWorldServerHandler extends ChannelInboundHandlerAdapter {
if (msg instanceof HttpRequest) {
HttpRequest req = (HttpRequest) msg;
if (is100ContinueExpected(req)) {
if (HttpHeaders.is100ContinueExpected(req)) {
ctx.write(new DefaultFullHttpResponse(HTTP_1_1, CONTINUE));
}
boolean keepAlive = isKeepAlive(req);
boolean keepAlive = HttpHeaders.isKeepAlive(req);
FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, OK, Unpooled.wrappedBuffer(CONTENT));
response.headers().set(CONTENT_TYPE, "text/plain");
response.headers().set(CONTENT_LENGTH, response.content().readableBytes());

View File

@ -27,7 +27,7 @@ import io.netty.util.CharsetUtil;
public class HttpSnoopClientHandler extends SimpleChannelInboundHandler<HttpObject> {
@Override
public void channelRead0(ChannelHandlerContext ctx, HttpObject msg) throws Exception {
public void channelRead0(ChannelHandlerContext ctx, HttpObject msg) {
if (msg instanceof HttpResponse) {
HttpResponse response = (HttpResponse) msg;

View File

@ -29,7 +29,7 @@ import io.netty.handler.ssl.util.SelfSignedCertificate;
* An HTTP server that sends back the content of the received HTTP request
* in a pretty plaintext form.
*/
public class HttpSnoopServer {
public final class HttpSnoopServer {
static final boolean SSL = System.getProperty("ssl") != null;
static final int PORT = Integer.parseInt(System.getProperty("port", SSL? "8443" : "8080"));

View File

@ -40,7 +40,6 @@ import java.util.Map.Entry;
import java.util.Set;
import static io.netty.handler.codec.http.HttpHeaders.Names.*;
import static io.netty.handler.codec.http.HttpHeaders.*;
import static io.netty.handler.codec.http.HttpResponseStatus.*;
import static io.netty.handler.codec.http.HttpVersion.*;
@ -60,7 +59,7 @@ public class HttpSnoopServerHandler extends SimpleChannelInboundHandler<Object>
if (msg instanceof HttpRequest) {
HttpRequest request = this.request = (HttpRequest) msg;
if (is100ContinueExpected(request)) {
if (HttpHeaders.is100ContinueExpected(request)) {
send100Continue(ctx);
}
@ -69,7 +68,7 @@ public class HttpSnoopServerHandler extends SimpleChannelInboundHandler<Object>
buf.append("===================================\r\n");
buf.append("VERSION: ").append(request.getProtocolVersion()).append("\r\n");
buf.append("HOSTNAME: ").append(getHost(request, "unknown")).append("\r\n");
buf.append("HOSTNAME: ").append(HttpHeaders.getHost(request, "unknown")).append("\r\n");
buf.append("REQUEST_URI: ").append(request.getUri()).append("\r\n\r\n");
HttpHeaders headers = request.headers();
@ -145,7 +144,7 @@ public class HttpSnoopServerHandler extends SimpleChannelInboundHandler<Object>
private boolean writeResponse(HttpObject currentObj, ChannelHandlerContext ctx) {
// Decide whether to close the connection or not.
boolean keepAlive = isKeepAlive(request);
boolean keepAlive = HttpHeaders.isKeepAlive(request);
// Build the response object.
FullHttpResponse response = new DefaultFullHttpResponse(
HTTP_1_1, currentObj.getDecoderResult().isSuccess()? OK : BAD_REQUEST,

View File

@ -32,7 +32,7 @@ public class HttpUploadClientHandler extends SimpleChannelInboundHandler<HttpObj
private boolean readingChunks;
@Override
public void channelRead0(ChannelHandlerContext ctx, HttpObject msg) throws Exception {
public void channelRead0(ChannelHandlerContext ctx, HttpObject msg) {
if (msg instanceof HttpResponse) {
HttpResponse response = (HttpResponse) msg;

View File

@ -28,7 +28,7 @@ import io.netty.handler.ssl.util.SelfSignedCertificate;
/**
* A HTTP server showing how to use the HTTP multipart package for file uploads and decoding post data.
*/
public class HttpUploadServer {
public final class HttpUploadServer {
static final boolean SSL = System.getProperty("ssl") != null;
static final int PORT = Integer.parseInt(System.getProperty("port", SSL? "8443" : "8080"));

View File

@ -76,6 +76,7 @@ public class HttpUploadServerHandler extends SimpleChannelInboundHandler<HttpObj
new DefaultHttpDataFactory(DefaultHttpDataFactory.MINSIZE); // Disk if size exceed
private HttpPostRequestDecoder decoder;
static {
DiskFileUpload.deleteOnExitTemporaryFile = true; // should delete file
// on exit (in normal

View File

@ -24,6 +24,7 @@ import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.codec.http.DefaultFullHttpResponse;
import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.FullHttpResponse;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.websocketx.CloseWebSocketFrame;
import io.netty.handler.codec.http.websocketx.PingWebSocketFrame;
import io.netty.handler.codec.http.websocketx.PongWebSocketFrame;
@ -34,7 +35,6 @@ import io.netty.handler.codec.http.websocketx.WebSocketServerHandshakerFactory;
import io.netty.util.CharsetUtil;
import static io.netty.handler.codec.http.HttpHeaders.Names.*;
import static io.netty.handler.codec.http.HttpHeaders.*;
import static io.netty.handler.codec.http.HttpMethod.*;
import static io.netty.handler.codec.http.HttpResponseStatus.*;
import static io.netty.handler.codec.http.HttpVersion.*;
@ -49,7 +49,7 @@ public class WebSocketServerHandler extends SimpleChannelInboundHandler<Object>
private WebSocketServerHandshaker handshaker;
@Override
public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
public void channelRead0(ChannelHandlerContext ctx, Object msg) {
if (msg instanceof FullHttpRequest) {
handleHttpRequest(ctx, (FullHttpRequest) msg);
} else if (msg instanceof WebSocketFrame) {
@ -81,7 +81,7 @@ public class WebSocketServerHandler extends SimpleChannelInboundHandler<Object>
FullHttpResponse res = new DefaultFullHttpResponse(HTTP_1_1, OK, content);
res.headers().set(CONTENT_TYPE, "text/html; charset=UTF-8");
setContentLength(res, content.readableBytes());
HttpHeaders.setContentLength(res, content.readableBytes());
sendHttpResponse(ctx, req, res);
return;
@ -132,12 +132,12 @@ public class WebSocketServerHandler extends SimpleChannelInboundHandler<Object>
ByteBuf buf = Unpooled.copiedBuffer(res.getStatus().toString(), CharsetUtil.UTF_8);
res.content().writeBytes(buf);
buf.release();
setContentLength(res, res.content().readableBytes());
HttpHeaders.setContentLength(res, res.content().readableBytes());
}
// Send the response and close the connection if necessary.
ChannelFuture f = ctx.channel().writeAndFlush(res);
if (!isKeepAlive(req) || res.getStatus().code() != 200) {
if (!HttpHeaders.isKeepAlive(req) || res.getStatus().code() != 200) {
f.addListener(ChannelFutureListener.CLOSE);
}
}

View File

@ -45,7 +45,7 @@ import java.util.Arrays;
* ./run-example.sh spdy-client
* </pre>
*/
public class SpdyClient {
public final class SpdyClient {
static final boolean SSL = System.getProperty("ssl") != null;
static final String HOST = System.getProperty("host", "127.0.0.1");

View File

@ -27,7 +27,7 @@ import io.netty.handler.ssl.util.SelfSignedCertificate;
/**
* Simplistic telnet server.
*/
public class TelnetServer {
public final class TelnetServer {
static final boolean SSL = System.getProperty("ssl") != null;
static final int PORT = Integer.parseInt(System.getProperty("port", SSL? "8992" : "8023"));

View File

@ -40,8 +40,8 @@ import java.util.concurrent.ThreadFactory;
public class ByteEchoPeerBase {
protected final int messageSize;
protected SocketAddress myAddress;
protected SocketAddress peerAddress;
protected final SocketAddress myAddress;
protected final SocketAddress peerAddress;
public ByteEchoPeerBase(int messageSize, SocketAddress myAddress, SocketAddress peerAddress) {
this.messageSize = messageSize;

View File

@ -10,7 +10,7 @@
<textarea id="responseText"></textarea>
<script>
function simpleGetRequest() {
var xhr = new XMLHttpRequest()
var xhr = new XMLHttpRequest();
xhr.open('GET', 'http://localhost:8080/cors');
// Uncomment to force a CORS preflight request.
@ -18,13 +18,13 @@
xhr.onerror = function() {
getTextAreaElement().value = 'CORS is NOT working';
}
};
xhr.onload = function() {
getTextAreaElement().value = 'CORS is working';
//var header = xhr.getResponseHeader("custom-response-header");
//appendTextArea('custom-response-header=' + header);
}
};
function getTextAreaElement() {
return document.getElementById('responseText');

View File

@ -260,10 +260,7 @@ public abstract class AbstractTrafficShapingHandler extends ChannelDuplexHandler
private static boolean isSuspended(ChannelHandlerContext ctx) {
Boolean suspended = ctx.attr(READ_SUSPENDED).get();
if (suspended == null || Boolean.FALSE.equals(suspended)) {
return false;
}
return true;
return !(suspended == null || Boolean.FALSE.equals(suspended));
}
@Override

View File

@ -1165,7 +1165,7 @@
</goals>
</pluginExecutionFilter>
<action>
<ignore />
<ignore/>
</action>
</pluginExecution>
<pluginExecution>
@ -1179,7 +1179,7 @@
</goals>
</pluginExecutionFilter>
<action>
<ignore />
<ignore/>
</action>
</pluginExecution>
</pluginExecutions>

View File

@ -61,9 +61,10 @@ public final class EpollDatagramChannel extends AbstractEpollChannel implements
}
@Override
@SuppressWarnings("deprecation")
public boolean isActive() {
return fd != -1 &&
((config.getOption(ChannelOption.DATAGRAM_CHANNEL_ACTIVE_ON_REGISTRATION) && isRegistered())
(config.getOption(ChannelOption.DATAGRAM_CHANNEL_ACTIVE_ON_REGISTRATION) && isRegistered()
|| active);
}
@ -278,7 +279,6 @@ public final class EpollDatagramChannel extends AbstractEpollChannel implements
InetSocketAddress remoteAddress;
ByteBuf data;
if (msg instanceof DatagramPacket) {
@SuppressWarnings("unchecked")
DatagramPacket packet = (DatagramPacket) msg;
remoteAddress = packet.recipient();
m = packet.content();
@ -464,6 +464,9 @@ public final class EpollDatagramChannel extends AbstractEpollChannel implements
* to create more objects then needed.
*/
static final class DatagramSocketAddress extends InetSocketAddress {
private static final long serialVersionUID = 1348596211215015739L;
// holds the amount of received bytes
final int receivedAmount;

View File

@ -39,6 +39,7 @@ public final class EpollDatagramChannelConfig extends DefaultChannelConfig imple
}
@Override
@SuppressWarnings("deprecation")
public Map<ChannelOption<?>, Object> getOptions() {
return getOptions(
super.getOptions(),
@ -49,7 +50,7 @@ public final class EpollDatagramChannelConfig extends DefaultChannelConfig imple
EpollChannelOption.SO_REUSEPORT);
}
@SuppressWarnings("unchecked")
@SuppressWarnings({ "unchecked", "deprecation" })
@Override
public <T> T getOption(ChannelOption<T> option) {
if (option == ChannelOption.SO_BROADCAST) {
@ -68,12 +69,10 @@ public final class EpollDatagramChannelConfig extends DefaultChannelConfig imple
return (T) Boolean.valueOf(isLoopbackModeDisabled());
}
if (option == ChannelOption.IP_MULTICAST_ADDR) {
T i = (T) getInterface();
return i;
return (T) getInterface();
}
if (option == ChannelOption.IP_MULTICAST_IF) {
T i = (T) getNetworkInterface();
return i;
return (T) getNetworkInterface();
}
if (option == ChannelOption.IP_MULTICAST_TTL) {
return (T) Integer.valueOf(getTimeToLive());
@ -91,6 +90,7 @@ public final class EpollDatagramChannelConfig extends DefaultChannelConfig imple
}
@Override
@SuppressWarnings("deprecation")
public <T> boolean setOption(ChannelOption<T> option, T value) {
validate(option, value);

View File

@ -27,10 +27,9 @@ import java.util.Map;
import static io.netty.channel.ChannelOption.*;
public final class EpollSocketChannelConfig extends DefaultChannelConfig
implements SocketChannelConfig {
public final class EpollSocketChannelConfig extends DefaultChannelConfig implements SocketChannelConfig {
protected final EpollSocketChannel channel;
private final EpollSocketChannel channel;
private volatile boolean allowHalfClosure;
/**

Some files were not shown because too many files have changed in this diff Show More