The query protocol in the Minecraft server has an I/O bug that is dependent upon the default charset used in the host system. Currently, integers are unpacked via code equivalent to the following: http://pastebin.com/raw.php?i=pNRJgzyB
This is unreliable, and will not properly unpack the integer into bytes. As a result, the Minecraft server will not always send back the proper session ID. Session IDs are sent back properly for the first 128 numbers on most charsets, but after that point the bug occurs.
We discovered this bug while writing software that polls information from over 20,000 Minecraft servers simultaneously for our website, Minestatus. It sure caused us quite a headache! We have implemented our own workaround that allows us to properly update all of our servers by generating session IDs that will come back correctly, but it was not simple. We recommend the following methods be used instead to unpack/pack integers/bytes: http://pastebin.com/raw.php?i=eeX59pHz
These two methods will guarantee that all session IDs will be unpacked and packed properly.
Thank you for your time.