From d54678d6450ee1f9555ff9520a716f9e643aface Mon Sep 17 00:00:00 2001 From: jimin Date: Thu, 4 Jul 2019 14:51:47 +0800 Subject: [PATCH] Remove unnecessary code (#9303) Motivation: There are is some unnecessary code (like toString() calls) which can be cleaned up. Modifications: - Remove not needed toString() calls - Simplify subString(...) calls - Remove some explicit casts when not needed. Result: Cleaner code --- .../handler/codec/http/CombinedHttpHeadersTest.java | 10 +++++----- .../handler/codec/http/HttpContentCompressorTest.java | 6 +++--- .../java/io/netty/handler/codec/xml/XmlDecoder.java | 2 +- .../io/netty/handler/codec/ByteToMessageCodecTest.java | 2 +- common/src/main/java/io/netty/util/NetUtil.java | 2 +- .../java/io/netty/util/internal/PlatformDependent.java | 4 ++-- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/CombinedHttpHeadersTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/CombinedHttpHeadersTest.java index a8134f2079..20230300aa 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/CombinedHttpHeadersTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/CombinedHttpHeadersTest.java @@ -55,7 +55,7 @@ public class CombinedHttpHeadersTest { otherHeaders.add(HEADER_NAME, "a"); otherHeaders.add(HEADER_NAME, "b"); headers.add(otherHeaders); - assertEquals("a,b", headers.get(HEADER_NAME).toString()); + assertEquals("a,b", headers.get(HEADER_NAME)); } @Test @@ -66,7 +66,7 @@ public class CombinedHttpHeadersTest { otherHeaders.add(HEADER_NAME, "b"); otherHeaders.add(HEADER_NAME, "c"); headers.add(otherHeaders); - assertEquals("a,b,c", headers.get(HEADER_NAME).toString()); + assertEquals("a,b,c", headers.get(HEADER_NAME)); } @Test @@ -99,7 +99,7 @@ public class CombinedHttpHeadersTest { otherHeaders.add(HEADER_NAME, "b"); otherHeaders.add(HEADER_NAME, "c"); headers.set(otherHeaders); - assertEquals("b,c", headers.get(HEADER_NAME).toString()); + assertEquals("b,c", headers.get(HEADER_NAME)); } @Test @@ -110,7 +110,7 @@ public class CombinedHttpHeadersTest { otherHeaders.add(HEADER_NAME, "b"); otherHeaders.add(HEADER_NAME, "c"); headers.add(otherHeaders); - assertEquals("a,b,c", headers.get(HEADER_NAME).toString()); + assertEquals("a,b,c", headers.get(HEADER_NAME)); } @Test @@ -121,7 +121,7 @@ public class CombinedHttpHeadersTest { otherHeaders.add(HEADER_NAME, "b"); otherHeaders.add(HEADER_NAME, "c"); headers.set(otherHeaders); - assertEquals("b,c", headers.get(HEADER_NAME).toString()); + assertEquals("b,c", headers.get(HEADER_NAME)); } @Test diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/HttpContentCompressorTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/HttpContentCompressorTest.java index 508eb5ae54..a31bc5beb8 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/HttpContentCompressorTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/HttpContentCompressorTest.java @@ -272,7 +272,7 @@ public class HttpContentCompressorTest { assertEncodedResponse(ch); ch.writeOutbound(LastHttpContent.EMPTY_LAST_CONTENT); - HttpContent chunk = (HttpContent) ch.readOutbound(); + HttpContent chunk = ch.readOutbound(); assertThat(ByteBufUtil.hexDump(chunk.content()), is("1f8b080000000000000003000000000000000000")); assertThat(chunk, is(instanceOf(HttpContent.class))); chunk.release(); @@ -423,7 +423,7 @@ public class HttpContentCompressorTest { res.headers().set(HttpHeaderNames.CONTENT_ENCODING, HttpHeaderValues.IDENTITY); assertTrue(ch.writeOutbound(res)); - FullHttpResponse response = (FullHttpResponse) ch.readOutbound(); + FullHttpResponse response = ch.readOutbound(); assertEquals(String.valueOf(len), response.headers().get(HttpHeaderNames.CONTENT_LENGTH)); assertEquals(HttpHeaderValues.IDENTITY.toString(), response.headers().get(HttpHeaderNames.CONTENT_ENCODING)); assertEquals("Hello, World", response.content().toString(CharsetUtil.US_ASCII)); @@ -445,7 +445,7 @@ public class HttpContentCompressorTest { res.headers().set(HttpHeaderNames.CONTENT_ENCODING, "ascii"); assertTrue(ch.writeOutbound(res)); - FullHttpResponse response = (FullHttpResponse) ch.readOutbound(); + FullHttpResponse response = ch.readOutbound(); assertEquals(String.valueOf(len), response.headers().get(HttpHeaderNames.CONTENT_LENGTH)); assertEquals("ascii", response.headers().get(HttpHeaderNames.CONTENT_ENCODING)); assertEquals("Hello, World", response.content().toString(CharsetUtil.US_ASCII)); diff --git a/codec-xml/src/main/java/io/netty/handler/codec/xml/XmlDecoder.java b/codec-xml/src/main/java/io/netty/handler/codec/xml/XmlDecoder.java index 7408848068..e84e5952f8 100644 --- a/codec-xml/src/main/java/io/netty/handler/codec/xml/XmlDecoder.java +++ b/codec-xml/src/main/java/io/netty/handler/codec/xml/XmlDecoder.java @@ -39,7 +39,7 @@ public class XmlDecoder extends ByteToMessageDecoder { private static final XmlDocumentEnd XML_DOCUMENT_END = XmlDocumentEnd.INSTANCE; private final AsyncXMLStreamReader streamReader = XML_INPUT_FACTORY.createAsyncForByteArray(); - private final AsyncByteArrayFeeder streamFeeder = (AsyncByteArrayFeeder) streamReader.getInputFeeder(); + private final AsyncByteArrayFeeder streamFeeder = streamReader.getInputFeeder(); @Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List out) throws Exception { diff --git a/codec/src/test/java/io/netty/handler/codec/ByteToMessageCodecTest.java b/codec/src/test/java/io/netty/handler/codec/ByteToMessageCodecTest.java index a1cb4e4439..9078fe734b 100644 --- a/codec/src/test/java/io/netty/handler/codec/ByteToMessageCodecTest.java +++ b/codec/src/test/java/io/netty/handler/codec/ByteToMessageCodecTest.java @@ -64,7 +64,7 @@ public class ByteToMessageCodecTest { assertTrue(ch.finish()); assertEquals(1, (int) ch.readInbound()); - ByteBuf buf = (ByteBuf) ch.readInbound(); + ByteBuf buf = ch.readInbound(); assertEquals(Unpooled.wrappedBuffer(new byte[]{'0'}), buf); buf.release(); assertNull(ch.readInbound()); diff --git a/common/src/main/java/io/netty/util/NetUtil.java b/common/src/main/java/io/netty/util/NetUtil.java index d17a605326..554e1b1570 100644 --- a/common/src/main/java/io/netty/util/NetUtil.java +++ b/common/src/main/java/io/netty/util/NetUtil.java @@ -319,7 +319,7 @@ public final class NetUtil { if (line.startsWith(sysctlKey)) { for (int i = line.length() - 1; i > sysctlKey.length(); --i) { if (!Character.isDigit(line.charAt(i))) { - return Integer.valueOf(line.substring(i + 1, line.length())); + return Integer.valueOf(line.substring(i + 1)); } } } diff --git a/common/src/main/java/io/netty/util/internal/PlatformDependent.java b/common/src/main/java/io/netty/util/internal/PlatformDependent.java index 9bba9668df..c56db25eb0 100644 --- a/common/src/main/java/io/netty/util/internal/PlatformDependent.java +++ b/common/src/main/java/io/netty/util/internal/PlatformDependent.java @@ -1102,8 +1102,8 @@ public final class PlatformDependent { // Last resort: guess from VM name and then fall back to most common 64-bit mode. String vm = SystemPropertyUtil.get("java.vm.name", "").toLowerCase(Locale.US); - Pattern BIT_PATTERN = Pattern.compile("([1-9][0-9]+)-?bit"); - Matcher m = BIT_PATTERN.matcher(vm); + Pattern bitPattern = Pattern.compile("([1-9][0-9]+)-?bit"); + Matcher m = bitPattern.matcher(vm); if (m.find()) { return Integer.parseInt(m.group(1)); } else {