Motivation: Sonar points out an equals comparison, where the types compared are different and don't share any common parent http://clinker.netty.io/sonar/drilldown/issues/io.netty:netty-parent:master?severity=CRITICAL#
Modifications: Converted AsciiString into a String by calling toString() method before comparing with equals(). Also added a unit-test to show that it works. Result: Major violation is gone. Code is correct.
This commit is contained in:
parent
bd6d0f3fd5
commit
9ee75126eb
@ -457,7 +457,7 @@ public class HttpResponseStatus implements Comparable<HttpResponseStatus> {
|
||||
int code = Integer.parseInt(status.substring(0, space));
|
||||
String reasonPhrase = status.substring(space + 1);
|
||||
HttpResponseStatus responseStatus = valueOf(code);
|
||||
if (responseStatus.reasonPhrase().equals(reasonPhrase)) {
|
||||
if (responseStatus.reasonPhrase().toString().equals(reasonPhrase)) {
|
||||
return responseStatus;
|
||||
} else {
|
||||
return new HttpResponseStatus(code, reasonPhrase);
|
||||
|
@ -23,6 +23,7 @@ import java.nio.CharBuffer;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.CharsetEncoder;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
@ -79,6 +80,13 @@ public class AsciiStringTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testComparisonWithString() {
|
||||
String string = "shouldn't fail";
|
||||
AsciiString ascii = new AsciiString(string.toCharArray());
|
||||
Assert.assertEquals(string, ascii.toString());
|
||||
}
|
||||
|
||||
private static byte[] getBytesWithEncoder(CharSequence value, Charset charset) {
|
||||
final CharsetEncoder encoder = CharsetUtil.getEncoder(charset);
|
||||
final ByteBuffer nativeBuffer = ByteBuffer.allocate((int) (encoder.maxBytesPerChar() * value.length()));
|
||||
|
Loading…
Reference in New Issue
Block a user