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:
Leonardo Freitas Gomes 2014-12-14 14:35:43 +01:00 committed by Norman Maurer
parent bd6d0f3fd5
commit 9ee75126eb
2 changed files with 9 additions and 1 deletions

View File

@ -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);

View File

@ -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()));