Make variables final (#11548)

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`.
This commit is contained in:
Aayush Atharva 2021-08-06 12:57:12 +05:30 committed by GitHub
parent a3c4c9ebfd
commit fe7b18ee83
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 26 additions and 25 deletions

View File

@ -42,7 +42,7 @@ public abstract class AbstractReferenceCountedByteBuf extends AbstractByteBuf {
};
// 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) {

View File

@ -667,7 +667,7 @@ public class ByteBufUtilTest {
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 }
};

View File

@ -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}.

View File

@ -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

View File

@ -27,8 +27,8 @@ import java.nio.charset.Charset;
* 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;

View File

@ -24,7 +24,7 @@ import org.mockito.stubbing.Answer;
abstract class AbstractWeightedFairQueueByteDistributorDependencyTest {
Http2Connection connection;
WeightedFairQueueByteDistributor distributor;
private IntObjectMap<TestStreamByteDistributorStreamState> stateMap =
private final IntObjectMap<TestStreamByteDistributorStreamState> stateMap =
new IntObjectHashMap<TestStreamByteDistributorStreamState>();
@Mock

View File

@ -242,6 +242,7 @@ final class HpackTestCase {
}
static class HeaderBlock {
@SuppressWarnings("FieldMayBeFinal")
private int maxHeaderTableSize = -1;
private byte[] encodedBytes;
private List<String> encoded;

View File

@ -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.

View File

@ -356,7 +356,7 @@ public final class MqttMessageBuilders {
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;

View File

@ -56,7 +56,7 @@ public final class FixedRedisMessagePool implements RedisMessagePool {
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;

View File

@ -404,7 +404,7 @@ public abstract class ZlibTest {
}
private static final class TestByteBufAllocator extends AbstractByteBufAllocator {
private ByteBufAllocator wrapped;
private final ByteBufAllocator wrapped;
private int maxAllocation;
TestByteBufAllocator(ByteBufAllocator wrapped) {

View File

@ -41,7 +41,7 @@ public abstract class AbstractReferenceCounted implements ReferenceCounted {
};
// 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

View File

@ -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() {

View File

@ -37,7 +37,7 @@ public class ResourceLeakDetectorTest {
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() {

View File

@ -147,7 +147,7 @@ public class FileRegionThrottleTest {
private static final class ReadHandler extends ChannelInboundHandlerAdapter {
private long bytesTransferred;
private CountDownLatch latch;
private final CountDownLatch latch;
ReadHandler(CountDownLatch latch) {
this.latch = latch;

View File

@ -34,9 +34,9 @@ import static io.netty.handler.codec.http.HttpConstants.*;
@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 {

View File

@ -115,7 +115,7 @@ public class Http2FrameWriterDataBenchmark extends AbstractMicrobenchmark {
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) {

View File

@ -25,7 +25,7 @@ import io.netty.util.internal.ObjectUtil;
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) {

View File

@ -98,7 +98,7 @@ public class NoPriorityByteDistributionBenchmark extends AbstractMicrobenchmark
}
}
private Http2StreamVisitor invocationVisitor = new Http2StreamVisitor() {
private final Http2StreamVisitor invocationVisitor = new Http2StreamVisitor() {
@Override
public boolean visit(Http2Stream stream) throws Http2Exception {
// Restore the connection window.

View File

@ -64,7 +64,7 @@ public class AbstractSharedExecutorMicrobenchmark extends AbstractMicrobenchmark
*/
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);

View File

@ -191,7 +191,7 @@ class TestDnsServer extends DnsServer {
@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 {

View File

@ -29,7 +29,7 @@ import static org.mockito.Mockito.when;
public class AdaptiveRecvByteBufAllocatorTest {
@Mock
private ChannelConfig config;
private ByteBufAllocator alloc = UnpooledByteBufAllocator.DEFAULT;
private final ByteBufAllocator alloc = UnpooledByteBufAllocator.DEFAULT;
private RecvByteBufAllocator.ExtendedHandle handle;
@BeforeEach

View File

@ -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;