From 5b55ee434b8d5434cfbd8186a00dfd1ff382b93a Mon Sep 17 00:00:00 2001 From: Artem Smotrakov Date: Mon, 12 Oct 2020 09:33:47 +0200 Subject: [PATCH] Avoid casting numbers to narrower types (#10645) Motivation: Avoid implicit conversions to narrower types in AbstractMemoryHttpData and Bzip2HuffmanStageEncoder classes reported by LGTM. Modifications: Updated the classes to avoid implicit casting to narrower types. It doesn't look like that an integer overflow is possible there, therefore no checks for overflows were added. Result: No warnings about implicit conversions to narrower types. --- .../handler/codec/http/multipart/AbstractMemoryHttpData.java | 2 +- .../handler/codec/compression/Bzip2HuffmanStageEncoder.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/multipart/AbstractMemoryHttpData.java b/codec-http/src/main/java/io/netty/handler/codec/http/multipart/AbstractMemoryHttpData.java index a07e61182b..a57619a5ad 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/multipart/AbstractMemoryHttpData.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/multipart/AbstractMemoryHttpData.java @@ -237,7 +237,7 @@ public abstract class AbstractMemoryHttpData extends AbstractHttpData { return true; } int length = byteBuf.readableBytes(); - int written = 0; + long written = 0; RandomAccessFile accessFile = new RandomAccessFile(dest, "rw"); try { FileChannel fileChannel = accessFile.getChannel(); diff --git a/codec/src/main/java/io/netty/handler/codec/compression/Bzip2HuffmanStageEncoder.java b/codec/src/main/java/io/netty/handler/codec/compression/Bzip2HuffmanStageEncoder.java index f026ba5633..797dc86428 100644 --- a/codec/src/main/java/io/netty/handler/codec/compression/Bzip2HuffmanStageEncoder.java +++ b/codec/src/main/java/io/netty/handler/codec/compression/Bzip2HuffmanStageEncoder.java @@ -219,7 +219,7 @@ final class Bzip2HuffmanStageEncoder { final int groupEnd = Math.min(groupStart + HUFFMAN_GROUP_RUN_LENGTH, mtfLength) - 1; // Calculate the cost of this group when encoded by each table - short[] cost = new short[totalTables]; + int[] cost = new int[totalTables]; for (int i = groupStart; i <= groupEnd; i++) { final int value = mtfBlock[i]; for (int j = 0; j < totalTables; j++) {