Skip to content

Commit a0656d2

Browse files
slievrlynormanmaurer
authored andcommitted
Remove unnecessary code (netty#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
1 parent 707c95e commit a0656d2

File tree

8 files changed

+14
-15
lines changed

8 files changed

+14
-15
lines changed

codec-http/src/test/java/io/netty/handler/codec/http/CombinedHttpHeadersTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public void addCombinedHeadersWhenEmpty() {
5555
otherHeaders.add(HEADER_NAME, "a");
5656
otherHeaders.add(HEADER_NAME, "b");
5757
headers.add(otherHeaders);
58-
assertEquals("a,b", headers.get(HEADER_NAME).toString());
58+
assertEquals("a,b", headers.get(HEADER_NAME));
5959
}
6060

6161
@Test
@@ -66,7 +66,7 @@ public void addCombinedHeadersWhenNotEmpty() {
6666
otherHeaders.add(HEADER_NAME, "b");
6767
otherHeaders.add(HEADER_NAME, "c");
6868
headers.add(otherHeaders);
69-
assertEquals("a,b,c", headers.get(HEADER_NAME).toString());
69+
assertEquals("a,b,c", headers.get(HEADER_NAME));
7070
}
7171

7272
@Test
@@ -99,7 +99,7 @@ public void setCombinedHeadersWhenNotEmpty() {
9999
otherHeaders.add(HEADER_NAME, "b");
100100
otherHeaders.add(HEADER_NAME, "c");
101101
headers.set(otherHeaders);
102-
assertEquals("b,c", headers.get(HEADER_NAME).toString());
102+
assertEquals("b,c", headers.get(HEADER_NAME));
103103
}
104104

105105
@Test
@@ -110,7 +110,7 @@ public void addUncombinedHeaders() {
110110
otherHeaders.add(HEADER_NAME, "b");
111111
otherHeaders.add(HEADER_NAME, "c");
112112
headers.add(otherHeaders);
113-
assertEquals("a,b,c", headers.get(HEADER_NAME).toString());
113+
assertEquals("a,b,c", headers.get(HEADER_NAME));
114114
}
115115

116116
@Test
@@ -121,7 +121,7 @@ public void setUncombinedHeaders() {
121121
otherHeaders.add(HEADER_NAME, "b");
122122
otherHeaders.add(HEADER_NAME, "c");
123123
headers.set(otherHeaders);
124-
assertEquals("b,c", headers.get(HEADER_NAME).toString());
124+
assertEquals("b,c", headers.get(HEADER_NAME));
125125
}
126126

127127
@Test

codec-http/src/test/java/io/netty/handler/codec/http/HttpContentCompressorTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ public void testEmptySplitContent() throws Exception {
272272
assertEncodedResponse(ch);
273273

274274
ch.writeOutbound(LastHttpContent.EMPTY_LAST_CONTENT);
275-
HttpContent chunk = (HttpContent) ch.readOutbound();
275+
HttpContent chunk = ch.readOutbound();
276276
assertThat(ByteBufUtil.hexDump(chunk.content()), is("1f8b080000000000000003000000000000000000"));
277277
assertThat(chunk, is(instanceOf(HttpContent.class)));
278278
chunk.release();
@@ -423,7 +423,7 @@ public void testIdentity() throws Exception {
423423
res.headers().set(HttpHeaderNames.CONTENT_ENCODING, HttpHeaderValues.IDENTITY);
424424
assertTrue(ch.writeOutbound(res));
425425

426-
FullHttpResponse response = (FullHttpResponse) ch.readOutbound();
426+
FullHttpResponse response = ch.readOutbound();
427427
assertEquals(String.valueOf(len), response.headers().get(HttpHeaderNames.CONTENT_LENGTH));
428428
assertEquals(HttpHeaderValues.IDENTITY.toString(), response.headers().get(HttpHeaderNames.CONTENT_ENCODING));
429429
assertEquals("Hello, World", response.content().toString(CharsetUtil.US_ASCII));
@@ -445,7 +445,7 @@ public void testCustomEncoding() throws Exception {
445445
res.headers().set(HttpHeaderNames.CONTENT_ENCODING, "ascii");
446446
assertTrue(ch.writeOutbound(res));
447447

448-
FullHttpResponse response = (FullHttpResponse) ch.readOutbound();
448+
FullHttpResponse response = ch.readOutbound();
449449
assertEquals(String.valueOf(len), response.headers().get(HttpHeaderNames.CONTENT_LENGTH));
450450
assertEquals("ascii", response.headers().get(HttpHeaderNames.CONTENT_ENCODING));
451451
assertEquals("Hello, World", response.content().toString(CharsetUtil.US_ASCII));

codec-xml/src/main/java/io/netty/handler/codec/xml/XmlDecoder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class XmlDecoder extends ByteToMessageDecoder {
3939
private static final XmlDocumentEnd XML_DOCUMENT_END = XmlDocumentEnd.INSTANCE;
4040

4141
private final AsyncXMLStreamReader<AsyncByteArrayFeeder> streamReader = XML_INPUT_FACTORY.createAsyncForByteArray();
42-
private final AsyncByteArrayFeeder streamFeeder = (AsyncByteArrayFeeder) streamReader.getInputFeeder();
42+
private final AsyncByteArrayFeeder streamFeeder = streamReader.getInputFeeder();
4343

4444
@Override
4545
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {

codec/src/test/java/io/netty/handler/codec/ByteToMessageCodecTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) t
6464
assertTrue(ch.finish());
6565
assertEquals(1, ch.readInbound());
6666

67-
ByteBuf buf = (ByteBuf) ch.readInbound();
67+
ByteBuf buf = ch.readInbound();
6868
assertEquals(Unpooled.wrappedBuffer(new byte[]{'0'}), buf);
6969
buf.release();
7070
assertNull(ch.readInbound());

common/src/main/java/io/netty/util/NetUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ private static Integer sysctlGetInt(String sysctlKey) throws IOException {
323323
if (line.startsWith(sysctlKey)) {
324324
for (int i = line.length() - 1; i > sysctlKey.length(); --i) {
325325
if (!Character.isDigit(line.charAt(i))) {
326-
return Integer.valueOf(line.substring(i + 1, line.length()));
326+
return Integer.valueOf(line.substring(i + 1));
327327
}
328328
}
329329
}

common/src/main/java/io/netty/util/internal/NativeLibraryLoader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public static void load(String originalName, ClassLoader loader) {
178178

179179
int index = libname.lastIndexOf('.');
180180
String prefix = libname.substring(0, index);
181-
String suffix = libname.substring(index, libname.length());
181+
String suffix = libname.substring(index);
182182

183183
tmpFile = File.createTempFile(prefix, suffix, WORKDIR);
184184
in = url.openStream();

common/src/main/java/io/netty/util/internal/PlatformDependent.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,8 +1188,8 @@ private static int bitMode0() {
11881188

11891189
// Last resort: guess from VM name and then fall back to most common 64-bit mode.
11901190
String vm = SystemPropertyUtil.get("java.vm.name", "").toLowerCase(Locale.US);
1191-
Pattern BIT_PATTERN = Pattern.compile("([1-9][0-9]+)-?bit");
1192-
Matcher m = BIT_PATTERN.matcher(vm);
1191+
Pattern bitPattern = Pattern.compile("([1-9][0-9]+)-?bit");
1192+
Matcher m = bitPattern.matcher(vm);
11931193
if (m.find()) {
11941194
return Integer.parseInt(m.group(1));
11951195
} else {

transport-udt/src/test/java/io/netty/test/udt/util/CaliperBench.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ protected void markWait(final long time) throws Exception {
9191
return;
9292
} else {
9393
System.out.print("-");
94-
continue;
9594
}
9695
}
9796
}

0 commit comments

Comments
 (0)