Datagram.java- Parsing Error
Brought to you by:
sasha-m
DG_MOVE_LIST can cause the datagram parsing logic in free.chessclub.level2.Datagram to throw a StringIndexOutOfBoundsException. This happens when the game doesn't yet have any moves (and thus there is an extra unexpected space at the end of the datagram).
In the code below, you'll notice that if the space is at the very end before the }, then startIndex will be equal to the StringLength.
while (firstChar == ' '){ // Skip any extra spaces just in case
index++;
firstChar = dgString.charAt(index);
}
startIndex = index;
endIndex = dgString.indexOf(' ', startIndex);
I've attached a fixed version to this bug report.
Datagram.java which fixes bug.