Attention, this is an ugly one: A non deterministic Bug. It fails only 1 out of 10 (approximately).
java.io.IOException: Resetting to invalid mark
at java.io.BufferedInputStream.reset(Unknown Source)
In the getEncoding()-Method: To re-read() the input stream, the current read position is marked and the readlimit (maximum number of bytes to be read before the mark position gets invalidated) is given.
So far so good, but then an InputStreamReader comes into play. When you check the API-Doc you see this:
- To enable the efficient conversion of bytes to characters, more bytes may
- be read ahead from the underlying stream than are necessary to satisfy the
- current read operation.
Please notice the term "may"... So, when this happens the following reset() on the stream will throw the Exception because the mark position gets invalidated (the number of read bytes exceeds the readlimit).