Skip to content

Commit

Permalink
Fix most inspector warnings
Browse files Browse the repository at this point in the history
Motivation:

It's good to minimize potentially broken windows.

Modifications:

Fix most inspector warnings from our profile

Result:

Cleaner code
  • Loading branch information
trustin committed Jul 2, 2014
1 parent cea3b6b commit 330404d
Show file tree
Hide file tree
Showing 155 changed files with 439 additions and 618 deletions.
65 changes: 0 additions & 65 deletions .fbfilter.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public abstract class AbstractReferenceCountedByteBuf extends AbstractByteBuf {
refCntUpdater = updater;
}

@SuppressWarnings("FieldMayBeFinal")
private volatile int refCnt = 1;

protected AbstractReferenceCountedByteBuf(int maxCapacity) {
Expand Down
4 changes: 2 additions & 2 deletions buffer/src/main/java/io/netty/buffer/ByteBufInputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public String readLine() throws IOException {

loop: while (true) {
if (!buffer.isReadable()) {
return (lineBuf.length() > 0) ? lineBuf.toString() : null;
return lineBuf.length() > 0 ? lineBuf.toString() : null;
}

int c = buffer.readUnsignedByte();
Expand All @@ -198,7 +198,7 @@ public String readLine() throws IOException {
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;
Expand Down
2 changes: 0 additions & 2 deletions buffer/src/main/java/io/netty/buffer/CompositeByteBuf.java
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,6 @@ private void consolidateIfNeeded() {
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;
Expand Down Expand Up @@ -1098,7 +1097,6 @@ public int nioBufferCount() {
} 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ final class FixedCompositeByteBuf extends AbstractReferenceCountedByteBuf {
private final Object[] buffers;
private final boolean direct;

public FixedCompositeByteBuf(ByteBufAllocator allocator, ByteBuf... buffers) {
FixedCompositeByteBuf(ByteBufAllocator allocator, ByteBuf... buffers) {
super(Integer.MAX_VALUE);
if (buffers.length == 0) {
this.buffers = EMPTY;
Expand Down Expand Up @@ -204,7 +204,6 @@ public boolean isDirect() {

private Component findComponent(int index) {
int readable = 0;
//noinspection ForLoopReplaceableByForEach
for (int i = 0 ; i < buffers.length; i++) {
Component comp = null;
ByteBuf b;
Expand Down Expand Up @@ -545,7 +544,6 @@ public long memoryAddress() {

@Override
protected void deallocate() {
//noinspection ForLoopReplaceableByForEach
for (int i = 0; i < buffers.length; i++) {
buffer(i).release();
}
Expand Down
1 change: 0 additions & 1 deletion buffer/src/main/java/io/netty/buffer/PooledByteBuf.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ protected final void deallocate() {
}
}

@SuppressWarnings("unchecked")
private void recycle() {
recyclerHandle.recycle(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ public int setBytes(int index, ScatteringByteChannel in, int length) throws IOEx
tmpBuf.clear().position(index).limit(index + length);
try {
return in.read(tmpBuf);
} catch (ClosedChannelException e) {
} catch (ClosedChannelException ignored) {
return -1;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public int setBytes(int index, ScatteringByteChannel in, int length) throws IOEx
index = idx(index);
try {
return in.read((ByteBuffer) internalNioBuffer().clear().position(index).limit(index + length));
} catch (ClosedChannelException e) {
} catch (ClosedChannelException ignored) {
return -1;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ public int setBytes(int index, ScatteringByteChannel in, int length) throws IOEx
tmpBuf.clear().position(index).limit(index + length);
try {
return in.read(tmpBuf);
} catch (ClosedChannelException e) {
} catch (ClosedChannelException ignored) {
return -1;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -276,7 +276,7 @@ public ByteBuf copy(int index, int length) {
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));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion buffer/src/main/java/io/netty/buffer/SlicedByteBuf.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ public int setBytes(int index, ScatteringByteChannel in, int length) throws IOEx
tmpBuf.clear().position(index).limit(index + length);
try {
return in.read(tmpNioBuf);
} catch (ClosedChannelException e) {
} catch (ClosedChannelException ignored) {
return -1;
}
}
Expand All @@ -556,7 +556,7 @@ public ByteBuf copy(int index, int length) {
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));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ public int setBytes(int index, ScatteringByteChannel in, int length) throws IOEx
ensureAccessible();
try {
return in.read((ByteBuffer) internalNioBuffer().clear().position(index).limit(index + length));
} catch (ClosedChannelException e) {
} catch (ClosedChannelException ignored) {
return -1;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ public int setBytes(int index, ScatteringByteChannel in, int length) throws IOEx
tmpBuf.clear().position(index).limit(index + length);
try {
return in.read(tmpBuf);
} catch (ClosedChannelException e) {
} catch (ClosedChannelException ignored) {
return -1;
}
}
Expand Down
1 change: 1 addition & 0 deletions buffer/src/main/java/io/netty/buffer/WrappedByteBuf.java
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,7 @@ public int hashCode() {
}

@Override
@SuppressWarnings("EqualsWhichDoesntCheckParameterClass")
public boolean equals(Object obj) {
return buf.equals(obj);
}
Expand Down
13 changes: 6 additions & 7 deletions buffer/src/test/java/io/netty/buffer/AbstractByteBufTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@
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;
Expand Down Expand Up @@ -1477,6 +1475,7 @@ public void testSliceIndex() throws Exception {
}

@Test
@SuppressWarnings("ObjectEqualsNull")
public void testEquals() {
assertFalse(buffer.equals(null));
assertFalse(buffer.equals(new Object()));
Expand Down Expand Up @@ -1728,7 +1727,6 @@ public boolean process(byte value) throws Exception {
assertThat(lastIndex.get(), is(CAPACITY / 4));
}

@Ignore
@Test
public void testInternalNioBuffer() {
testInternalNioBuffer(128);
Expand Down Expand Up @@ -1796,7 +1794,7 @@ public void run() {
return;
}
}
Assert.assertArrayEquals(bytes, channel.writtenBytes());
assertArrayEquals(bytes, channel.writtenBytes());
latch.countDown();
}
try {
Expand Down Expand Up @@ -1850,7 +1848,7 @@ public void run() {
return;
}
}
Assert.assertArrayEquals(bytes, out.toByteArray());
assertArrayEquals(bytes, out.toByteArray());
latch.countDown();
}
try {
Expand Down Expand Up @@ -1899,11 +1897,11 @@ public void run() {
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();
}
Expand All @@ -1929,6 +1927,7 @@ public void readByteThrowsIndexOutOfBoundsException() {
}

@Test
@SuppressWarnings("ForLoopThatDoesntUseLoopVariable")
public void testNioBufferExposeOnlyRegion() {
final ByteBuf buffer = releaseLater(newBuffer(8));
byte[] data = new byte[8];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ protected ByteBuf newBuffer(int length) {
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);
Expand Down Expand Up @@ -802,7 +801,7 @@ public void testDiscardSomeReadBytes() {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package io.netty.buffer;

import org.junit.Ignore;
import org.junit.Test;

import static org.junit.Assert.*;
Expand Down Expand Up @@ -44,14 +43,6 @@ public void shouldNotAllowNullInConstructor() {
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() {
Expand Down
6 changes: 3 additions & 3 deletions buffer/src/test/java/io/netty/buffer/ReadOnlyByteBufTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ public void testUnmodifiableBuffer() {
@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
Expand Down
Loading

0 comments on commit 330404d

Please sign in to comment.