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 09:27:12 +02:00 committed by Chris Vest
parent ea8f6774d5
commit 25a0a6d425
20 changed files with 23 additions and 22 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 // 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(); private volatile int refCnt = updater.initialValue();
protected AbstractReferenceCountedByteBuf(int maxCapacity) { protected AbstractReferenceCountedByteBuf(int maxCapacity) {

View File

@ -652,7 +652,7 @@ public class ByteBufUtilTest {
ByteBufUtil.utf8Bytes(usAscii, 5, 18)); 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 } { -1, 5 }, { 5, 30 }, { 10, 5 }
}; };

View File

@ -55,7 +55,7 @@ public class CorsHandler implements ChannelHandler {
private HttpRequest request; private HttpRequest request;
private final List<CorsConfig> configList; private final List<CorsConfig> configList;
private boolean isShortCircuit; private final boolean isShortCircuit;
/** /**
* Creates a new instance with a single {@link CorsConfig}. * Creates a new instance with a single {@link CorsConfig}.

View File

@ -102,7 +102,7 @@ public class HttpPostMultipartRequestDecoder implements InterfaceHttpPostRequest
/** /**
* If multipart, this is the boundary for the global multipart * 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 * 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 * Mixed implementation using both in Memory and in File with a limit of size
*/ */
public class MixedAttribute implements Attribute { public class MixedAttribute implements Attribute {
private String baseDir; private final String baseDir;
private boolean deleteOnExit; private final boolean deleteOnExit;
private Attribute attribute; private Attribute attribute;
private final long limitSize; private final long limitSize;

View File

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

View File

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

View File

@ -74,7 +74,7 @@ public class Http2ControlFrameLimitEncoderTest {
private int numWrites; private int numWrites;
private Queue<ChannelPromise> goAwayPromises = new ArrayDeque<ChannelPromise>(); private final Queue<ChannelPromise> goAwayPromises = new ArrayDeque<ChannelPromise>();
/** /**
* Init fields and do mocking. * Init fields and do mocking.

View File

@ -356,7 +356,7 @@ public final class MqttMessageBuilders {
private Long maximumPacketSize; private Long maximumPacketSize;
private int topicAliasMaximum; private int topicAliasMaximum;
private String reasonString; private String reasonString;
private MqttProperties.UserProperties userProperties = new MqttProperties.UserProperties(); private final MqttProperties.UserProperties userProperties = new MqttProperties.UserProperties();
private Boolean wildcardSubscriptionAvailable; private Boolean wildcardSubscriptionAvailable;
private Boolean subscriptionIdentifiersAvailable; private Boolean subscriptionIdentifiersAvailable;
private Boolean sharedSubscriptionAvailable; private Boolean sharedSubscriptionAvailable;

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 // 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(); private volatile int refCnt = updater.initialValue();
@Override @Override

View File

@ -36,7 +36,7 @@ public class AsciiStringMemoryTest {
private int length = 100; private int length = 100;
private AsciiString aAsciiString; private AsciiString aAsciiString;
private AsciiString bAsciiString; private AsciiString bAsciiString;
private Random r = new Random(); private final Random r = new Random();
@BeforeEach @BeforeEach
public void setup() { public void setup() {

View File

@ -37,7 +37,7 @@ public class ResourceLeakDetectorTest {
final CyclicBarrier barrier = new CyclicBarrier(threads.length); final CyclicBarrier barrier = new CyclicBarrier(threads.length);
for (int i = 0; i < threads.length; i++) { for (int i = 0; i < threads.length; i++) {
Thread t = new Thread(new Runnable() { Thread t = new Thread(new Runnable() {
Queue<LeakAwareResource> resources = new ArrayDeque<>(100); final Queue<LeakAwareResource> resources = new ArrayDeque<>(100);
@Override @Override
public void run() { public void run() {

View File

@ -34,9 +34,9 @@ import static io.netty.handler.codec.http.HttpConstants.*;
@Measurement(iterations = 20) @Measurement(iterations = 20)
public class HttpRequestEncoderInsertBenchmark extends AbstractMicrobenchmark { public class HttpRequestEncoderInsertBenchmark extends AbstractMicrobenchmark {
private String uri = "http://localhost?eventType=CRITICAL&from=0&to=1497437160327&limit=10&offset=0"; private final String uri = "http://localhost?eventType=CRITICAL&from=0&to=1497437160327&limit=10&offset=0";
private OldHttpRequestEncoder encoderOld = new OldHttpRequestEncoder(); private final OldHttpRequestEncoder encoderOld = new OldHttpRequestEncoder();
private HttpRequestEncoder encoderNew = new HttpRequestEncoder(); private final HttpRequestEncoder encoderNew = new HttpRequestEncoder();
@Benchmark @Benchmark
public ByteBuf oldEncoder() throws Exception { 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 class OldDefaultHttp2FrameWriter implements Http2DataWriter {
private static final ByteBuf ZERO_BUFFER = private static final ByteBuf ZERO_BUFFER =
unreleasableBuffer(directBuffer(MAX_UNSIGNED_BYTE).writeZero(MAX_UNSIGNED_BYTE)).asReadOnly(); 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 @Override
public ChannelFuture writeData(ChannelHandlerContext ctx, int streamId, ByteBuf data, public ChannelFuture writeData(ChannelHandlerContext ctx, int streamId, ByteBuf data,
int padding, boolean endStream, ChannelPromise promise) { int padding, boolean endStream, ChannelPromise promise) {

View File

@ -26,7 +26,7 @@ import io.netty.handler.codec.ByteToMessageDecoder;
public abstract class EmbeddedChannelWriteAccumulatingHandlerContext extends EmbeddedChannelHandlerContext { public abstract class EmbeddedChannelWriteAccumulatingHandlerContext extends EmbeddedChannelHandlerContext {
private ByteBuf cumulation; private ByteBuf cumulation;
private ByteToMessageDecoder.Cumulator cumulator; private final ByteToMessageDecoder.Cumulator cumulator;
protected EmbeddedChannelWriteAccumulatingHandlerContext(ByteBufAllocator alloc, ChannelHandler handler, protected EmbeddedChannelWriteAccumulatingHandlerContext(ByteBufAllocator alloc, ChannelHandler handler,
ByteToMessageDecoder.Cumulator writeCumulator) { ByteToMessageDecoder.Cumulator writeCumulator) {

View File

@ -98,7 +98,7 @@ public class NoPriorityByteDistributionBenchmark extends AbstractMicrobenchmark
} }
} }
private Http2StreamVisitor invocationVisitor = stream -> { private final Http2StreamVisitor invocationVisitor = stream -> {
// Restore the connection window. // Restore the connection window.
resetWindow(stream); resetWindow(stream);

View File

@ -65,7 +65,7 @@ public class AbstractSharedExecutorMicrobenchmark extends AbstractMicrobenchmark
*/ */
public static final class DelegateHarnessExecutor extends AbstractEventExecutor { public static final class DelegateHarnessExecutor extends AbstractEventExecutor {
private static EventLoop executor; 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) { public DelegateHarnessExecutor(int maxThreads, String prefix) {
logger.debug("Using DelegateHarnessExecutor executor {}", this); logger.debug("Using DelegateHarnessExecutor executor {}", this);

View File

@ -191,7 +191,7 @@ class TestDnsServer extends DnsServer {
@Override @Override
public ProtocolDecoder getDecoder(IoSession session) { public ProtocolDecoder getDecoder(IoSession session) {
return new ProtocolDecoderAdapter() { return new ProtocolDecoderAdapter() {
private DnsMessageDecoder decoder = new DnsMessageDecoder(); private final DnsMessageDecoder decoder = new DnsMessageDecoder();
@Override @Override
public void decode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws IOException { 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 { public class AdaptiveRecvByteBufAllocatorTest {
@Mock @Mock
private ChannelConfig config; private ChannelConfig config;
private ByteBufAllocator alloc = UnpooledByteBufAllocator.DEFAULT; private final ByteBufAllocator alloc = UnpooledByteBufAllocator.DEFAULT;
private RecvByteBufAllocator.ExtendedHandle handle; private RecvByteBufAllocator.ExtendedHandle handle;
@BeforeEach @BeforeEach

View File

@ -21,7 +21,7 @@ public class CustomChannelId implements ChannelId {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private int id; private final int id;
CustomChannelId(int id) { CustomChannelId(int id) {
this.id = id; this.id = id;