我有这样的代码,它在FindBugs中显示了以下错误:

Bug: Bad comparison of nonnegative value with -1 in hydra.extensions.drivers.eg2.internal.EG2GatewaySimulator$1.run()
This code compares a value that is guaranteed to be non-negative with a negative constant or zero.
Rank: Scary (5), confidence: High
Pattern: INT_BAD_COMPARISON_WITH_NONNEGATIVE_VALUE
Type: INT, Category: CORRECTNESS (Correctness)关于守则:
String receivedMessage = "";
char c;
boolean isValidChar;
do {
c = (char) in.read();
isValidChar = (c != '\r') && (c != -1);
if (isValidChar) {
receivedMessage += c;
}
} while (isValidChar);发布于 2015-10-30 15:26:06
字符值为16位,非负值:
char: char数据类型是单个16位Unicode字符.它的最小值为'\u0000‘(或0),最大值为'\uffff’(含65,535 )。
你在把它和-1比较。
https://stackoverflow.com/questions/33439412
复制相似问题