I may be misunderstanding, but this function seems not to have a while loop, and this new control flow does seem appropriate. In the function a [few lines above](https://github.com/hsaputra/incubator-spark/blob/6db8452241d53523ce7c06515994bcde174f9d7b/core/src/main/scala/org/apache/spark/network/BufferMessage.scala#L56), the while loop with a return statement is unchanged.