Remove unnecessary toString calls (#11550)

Motivation:
We should get rid of the unnecessary toString calls because they're redundant in nature.

Modification:
Removed unnecessary toString calls.

Result:
Better code
This commit is contained in:
Aayush Atharva 2021-08-05 17:47:00 +05:30 committed by Chris Vest
parent 1c574e0d22
commit 6d6d2060af
4 changed files with 13 additions and 13 deletions

View File

@ -286,14 +286,14 @@ public class HttpResponseEncoderTest {
ByteBuf buffer = channel.readOutbound(); ByteBuf buffer = channel.readOutbound();
StringBuilder responseText = new StringBuilder(); StringBuilder responseText = new StringBuilder();
responseText.append(HttpVersion.HTTP_1_1.toString()).append(' ').append(status.toString()).append("\r\n"); responseText.append(HttpVersion.HTTP_1_1).append(' ').append(status.toString()).append("\r\n");
if (!headerStripped && headerName != null) { if (!headerStripped && headerName != null) {
responseText.append(headerName).append(": "); responseText.append(headerName).append(": ");
if (HttpHeaderNames.CONTENT_LENGTH.contentEquals(headerName)) { if (HttpHeaderNames.CONTENT_LENGTH.contentEquals(headerName)) {
responseText.append('0'); responseText.append('0');
} else { } else {
responseText.append(HttpHeaderValues.CHUNKED.toString()); responseText.append(HttpHeaderValues.CHUNKED);
} }
responseText.append("\r\n"); responseText.append("\r\n");
} }
@ -383,8 +383,8 @@ public class HttpResponseEncoderTest {
assertTrue(channel.writeOutbound(LastHttpContent.EMPTY_LAST_CONTENT)); assertTrue(channel.writeOutbound(LastHttpContent.EMPTY_LAST_CONTENT));
StringBuilder responseText = new StringBuilder(); StringBuilder responseText = new StringBuilder();
responseText.append(HttpVersion.HTTP_1_1.toString()).append(' ') responseText.append(HttpVersion.HTTP_1_1).append(' ')
.append(HttpResponseStatus.RESET_CONTENT.toString()).append("\r\n"); .append(HttpResponseStatus.RESET_CONTENT).append("\r\n");
responseText.append(HttpHeaderNames.CONTENT_LENGTH).append(": 0\r\n"); responseText.append(HttpHeaderNames.CONTENT_LENGTH).append(": 0\r\n");
responseText.append("\r\n"); responseText.append("\r\n");

View File

@ -162,7 +162,7 @@ public class Http2StreamFrameToHttpObjectCodec extends MessageToMessageCodec<Htt
return; return;
} else { } else {
throw new EncoderException( throw new EncoderException(
HttpResponseStatus.CONTINUE.toString() + " must be a FullHttpResponse"); HttpResponseStatus.CONTINUE + " must be a FullHttpResponse");
} }
} }
} }

View File

@ -182,15 +182,15 @@ public final class MqttDecoder extends ReplayingDecoder<DecoderState> {
case SUBSCRIBE: case SUBSCRIBE:
case UNSUBSCRIBE: case UNSUBSCRIBE:
if (dupFlag) { if (dupFlag) {
throw new DecoderException("Illegal BIT 3 in fixed header of " + messageType.toString() throw new DecoderException("Illegal BIT 3 in fixed header of " + messageType
+ " message, must be 0, found 1"); + " message, must be 0, found 1");
} }
if (qosLevel != 1) { if (qosLevel != 1) {
throw new DecoderException("Illegal QOS Level in fixed header of " + messageType.toString() throw new DecoderException("Illegal QOS Level in fixed header of " + messageType
+ " message, must be 1, found " + qosLevel); + " message, must be 1, found " + qosLevel);
} }
if (retain) { if (retain) {
throw new DecoderException("Illegal BIT 0 in fixed header of " + messageType.toString() throw new DecoderException("Illegal BIT 0 in fixed header of " + messageType
+ " message, must be 0, found 1"); + " message, must be 0, found 1");
} }
break; break;
@ -207,15 +207,15 @@ public final class MqttDecoder extends ReplayingDecoder<DecoderState> {
case SUBACK: case SUBACK:
case UNSUBACK: case UNSUBACK:
if (dupFlag) { if (dupFlag) {
throw new DecoderException("Illegal BIT 3 in fixed header of " + messageType.toString() throw new DecoderException("Illegal BIT 3 in fixed header of " + messageType
+ " message, must be 0, found 1"); + " message, must be 0, found 1");
} }
if (qosLevel != 0) { if (qosLevel != 0) {
throw new DecoderException("Illegal BIT 2 or 1 in fixed header of " + messageType.toString() throw new DecoderException("Illegal BIT 2 or 1 in fixed header of " + messageType
+ " message, must be 0, found " + qosLevel); + " message, must be 0, found " + qosLevel);
} }
if (retain) { if (retain) {
throw new DecoderException("Illegal BIT 0 in fixed header of " + messageType.toString() throw new DecoderException("Illegal BIT 0 in fixed header of " + messageType
+ " message, must be 0, found 1"); + " message, must be 0, found 1");
} }
break; break;

View File

@ -343,9 +343,9 @@ public class StompSubframeDecoder extends ReplayingDecoder<State> {
headers.add(name, value.toString()); headers.add(name, value.toString());
} else if (validateHeaders) { } else if (validateHeaders) {
if (StringUtil.isNullOrEmpty(name)) { if (StringUtil.isNullOrEmpty(name)) {
throw new IllegalArgumentException("received an invalid header line '" + value.toString() + '\''); throw new IllegalArgumentException("received an invalid header line '" + value + '\'');
} }
String line = name + ':' + value.toString(); String line = name + ':' + value;
throw new IllegalArgumentException("a header value or name contains a prohibited character ':'" throw new IllegalArgumentException("a header value or name contains a prohibited character ':'"
+ ", " + line); + ", " + line);
} }