Skip to content

Commit

Permalink
Make variables final (netty#11548)
Browse files Browse the repository at this point in the history
Motivation:
We should make variables `final` which are not reinstated again in code to match the code style and makes the code look better.

Modification:
Made couples of variables as `final`.

Result:
Variables marked as `final`.
  • Loading branch information
hyperxpro authored Aug 6, 2021
1 parent a3c4c9e commit fe7b18e
Show file tree
Hide file tree
Showing 23 changed files with 26 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected long unsafeOffset() {
};

// Value might not equal "real" reference count, all access should be via the updater
@SuppressWarnings("unused")
@SuppressWarnings({"unused", "FieldMayBeFinal"})
private volatile int refCnt = updater.initialValue();

protected AbstractReferenceCountedByteBuf(int maxCapacity) {
Expand Down
2 changes: 1 addition & 1 deletion buffer/src/test/java/io/netty/buffer/ByteBufUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ public void testUtf8BytesSubsequence() {
ByteBufUtil.utf8Bytes(usAscii, 5, 18));
}

private static int[][] INVALID_RANGES = new int[][] {
private static final int[][] INVALID_RANGES = new int[][] {
{ -1, 5 }, { 5, 30 }, { 10, 5 }
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class CorsHandler extends ChannelDuplexHandler {

private HttpRequest request;
private final List<CorsConfig> configList;
private boolean isShortCircuit;
private final boolean isShortCircuit;

/**
* Creates a new instance with a single {@link CorsConfig}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public class HttpPostMultipartRequestDecoder implements InterfaceHttpPostRequest
/**
* If multipart, this is the boundary for the global multipart
*/
private String multipartDataBoundary;
private final String multipartDataBoundary;

/**
* If multipart, there could be internal multiparts (mixed) to the global
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
* Mixed implementation using both in Memory and in File with a limit of size
*/
public class MixedAttribute implements Attribute {
private String baseDir;
private boolean deleteOnExit;
private final String baseDir;
private final boolean deleteOnExit;
private Attribute attribute;

private final long limitSize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
abstract class AbstractWeightedFairQueueByteDistributorDependencyTest {
Http2Connection connection;
WeightedFairQueueByteDistributor distributor;
private IntObjectMap<TestStreamByteDistributorStreamState> stateMap =
private final IntObjectMap<TestStreamByteDistributorStreamState> stateMap =
new IntObjectHashMap<TestStreamByteDistributorStreamState>();

@Mock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ private static boolean headersEqual(List<HpackHeaderField> expected, List<HpackH
}

static class HeaderBlock {
@SuppressWarnings("FieldMayBeFinal")
private int maxHeaderTableSize = -1;
private byte[] encodedBytes;
private List<String> encoded;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public class Http2ControlFrameLimitEncoderTest {

private int numWrites;

private Queue<ChannelPromise> goAwayPromises = new ArrayDeque<ChannelPromise>();
private final Queue<ChannelPromise> goAwayPromises = new ArrayDeque<ChannelPromise>();

/**
* Init fields and do mocking.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ public static final class ConnAckPropertiesBuilder {
private Long maximumPacketSize;
private int topicAliasMaximum;
private String reasonString;
private MqttProperties.UserProperties userProperties = new MqttProperties.UserProperties();
private final MqttProperties.UserProperties userProperties = new MqttProperties.UserProperties();
private Boolean wildcardSubscriptionAvailable;
private Boolean subscriptionIdentifiersAvailable;
private Boolean sharedSubscriptionAvailable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public enum RedisErrorKey {
WRONGTYPE("WRONGTYPE Operation against a key holding the wrong kind of value"),
NOT_AUTH("NOAUTH Authentication required.");

private String msg;
private final String msg;

RedisErrorKey(String msg) {
this.msg = msg;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ private static byte[] deflate(byte[] bytes) throws IOException {
}

private static final class TestByteBufAllocator extends AbstractByteBufAllocator {
private ByteBufAllocator wrapped;
private final ByteBufAllocator wrapped;
private int maxAllocation;

TestByteBufAllocator(ByteBufAllocator wrapped) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected long unsafeOffset() {
};

// Value might not equal "real" reference count, all access should be via the updater
@SuppressWarnings("unused")
@SuppressWarnings({"unused", "FieldMayBeFinal"})
private volatile int refCnt = updater.initialValue();

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class AsciiStringMemoryTest {
private int length = 100;
private AsciiString aAsciiString;
private AsciiString bAsciiString;
private Random r = new Random();
private final Random r = new Random();

@BeforeEach
public void setup() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void testConcurrentUsage() throws Throwable {
final CyclicBarrier barrier = new CyclicBarrier(threads.length);
for (int i = 0; i < threads.length; i++) {
Thread t = new Thread(new Runnable() {
Queue<LeakAwareResource> resources = new ArrayDeque<LeakAwareResource>(100);
final Queue<LeakAwareResource> resources = new ArrayDeque<LeakAwareResource>(100);

@Override
public void run() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception

private static final class ReadHandler extends ChannelInboundHandlerAdapter {
private long bytesTransferred;
private CountDownLatch latch;
private final CountDownLatch latch;

ReadHandler(CountDownLatch latch) {
this.latch = latch;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
@Measurement(iterations = 20)
public class HttpRequestEncoderInsertBenchmark extends AbstractMicrobenchmark {

private String uri = "http://localhost?eventType=CRITICAL&from=0&to=1497437160327&limit=10&offset=0";
private OldHttpRequestEncoder encoderOld = new OldHttpRequestEncoder();
private HttpRequestEncoder encoderNew = new HttpRequestEncoder();
private final String uri = "http://localhost?eventType=CRITICAL&from=0&to=1497437160327&limit=10&offset=0";
private final OldHttpRequestEncoder encoderOld = new OldHttpRequestEncoder();
private final HttpRequestEncoder encoderNew = new HttpRequestEncoder();

@Benchmark
public ByteBuf oldEncoder() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public void oldWriter() {
private static final class OldDefaultHttp2FrameWriter implements Http2DataWriter {
private static final ByteBuf ZERO_BUFFER =
unreleasableBuffer(directBuffer(MAX_UNSIGNED_BYTE).writeZero(MAX_UNSIGNED_BYTE)).asReadOnly();
private int maxFrameSize = DEFAULT_MAX_FRAME_SIZE;
private final int maxFrameSize = DEFAULT_MAX_FRAME_SIZE;
@Override
public ChannelFuture writeData(ChannelHandlerContext ctx, int streamId, ByteBuf data,
int padding, boolean endStream, ChannelPromise promise) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

public abstract class EmbeddedChannelWriteAccumulatingHandlerContext extends EmbeddedChannelHandlerContext {
private ByteBuf cumulation;
private ByteToMessageDecoder.Cumulator cumulator;
private final ByteToMessageDecoder.Cumulator cumulator;

protected EmbeddedChannelWriteAccumulatingHandlerContext(ByteBufAllocator alloc, ChannelHandler handler,
ByteToMessageDecoder.Cumulator writeCumulator) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public int maxWriteSize() {
}
}

private Http2StreamVisitor invocationVisitor = new Http2StreamVisitor() {
private final Http2StreamVisitor invocationVisitor = new Http2StreamVisitor() {
@Override
public boolean visit(Http2Stream stream) throws Http2Exception {
// Restore the connection window.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static void executor(EventLoop eventLoop) {
*/
public static final class DelegateHarnessExecutor extends AbstractEventExecutor {
private static EventLoop executor;
private InternalLogger logger = InternalLoggerFactory.getInstance(DelegateHarnessExecutor.class);
private final InternalLogger logger = InternalLoggerFactory.getInstance(DelegateHarnessExecutor.class);

public DelegateHarnessExecutor(int maxThreads, String prefix) {
logger.debug("Using DelegateHarnessExecutor executor {}", this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public void encode(IoSession session, Object message, ProtocolEncoderOutput out)
@Override
public ProtocolDecoder getDecoder(IoSession session) {
return new ProtocolDecoderAdapter() {
private DnsMessageDecoder decoder = new DnsMessageDecoder();
private final DnsMessageDecoder decoder = new DnsMessageDecoder();

@Override
public void decode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
public class AdaptiveRecvByteBufAllocatorTest {
@Mock
private ChannelConfig config;
private ByteBufAllocator alloc = UnpooledByteBufAllocator.DEFAULT;
private final ByteBufAllocator alloc = UnpooledByteBufAllocator.DEFAULT;
private RecvByteBufAllocator.ExtendedHandle handle;

@BeforeEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class CustomChannelId implements ChannelId {

private static final long serialVersionUID = 1L;

private int id;
private final int id;

CustomChannelId(int id) {
this.id = id;
Expand Down

0 comments on commit fe7b18e

Please sign in to comment.