Program: 77167
Project: 77167
Buggy source:
/** 
 * Reads in a string that has been encoded using a <a href="../../../java/io/DataInput.html#modified-utf-8">modified UTF-8</a> format.  The general contract of <code>readUTF</code> is that it reads a representation of a Unicode character string encoded in modified UTF-8 format; this string of characters is then returned as a <code>String</code>. <p> First, two bytes are read and used to construct an unsigned 16-bit integer in the manner of the <code>readUnsignedShort</code> method, using network byte order (regardless of the current byte order setting). This integer value is called the <i>UTF length</i> and specifies the number of additional bytes to be read. These bytes are then converted to characters by considering them in groups. The length of each group is computed from the value of the first byte of the group. The byte following a group, if any, is the first byte of the next group. <p> If the first byte of a group matches the bit pattern <code>0xxxxxxx</code> (where <code>x</code> means "may be <code>0</code> or <code>1</code>"), then the group consists of just that byte. The byte is zero-extended to form a character. <p> If the first byte of a group matches the bit pattern <code>110xxxxx</code>, then the group consists of that byte <code>a</code> and a second byte <code>b</code>. If there is no byte <code>b</code> (because byte <code>a</code> was the last of the bytes to be read), or if byte <code>b</code> does not match the bit pattern <code>10xxxxxx</code>, then a <code>UTFDataFormatException</code> is thrown. Otherwise, the group is converted to the character: <p> <pre><code> (char)(((a&amp; 0x1F) &lt;&lt; 6) | (b &amp; 0x3F)) </code></pre> If the first byte of a group matches the bit pattern <code>1110xxxx</code>, then the group consists of that byte <code>a</code> and two more bytes <code>b</code> and <code>c</code>.  If there is no byte <code>c</code> (because byte <code>a</code> was one of the last two of the bytes to be read), or either byte <code>b</code> or byte <code>c</code> does not match the bit pattern <code>10xxxxxx</code>, then a <code>UTFDataFormatException</code> is thrown. Otherwise, the group is converted to the character: <p> <pre><code> (char)(((a &amp; 0x0F) &lt;&lt; 12) | ((b &amp; 0x3F) &lt;&lt; 6) | (c &amp; 0x3F)) </code></pre> If the first byte of a group matches the pattern <code>1111xxxx</code> or the pattern <code>10xxxxxx</code>, then a <code>UTFDataFormatException</code> is thrown. <p> If end of file is encountered at any time during this entire process, then an <code>java.io.EOFException</code> is thrown. <p> After every group has been converted to a character by this process, the characters are gathered, in the same order in which their corresponding groups were read from the input stream, to form a <code>String</code>, which is returned. <p> The current byte order setting is ignored. <p> The bit offset within the stream is reset to zero before the read occurs. <p><strong>Note:</strong> This method should not be used in the  implementation of image formats that use standard UTF-8, because  the modified UTF-8 used here is incompatible with standard UTF-8.
 * @return a String read from the stream.
 * @exception java.io.EOFException  if this stream reaches the endbefore reading all the bytes.
 * @exception java.io.UTFDataFormatException if the bytes do not representa valid modified UTF-8 encoding of a string.
 * @exception IOException if an I/O error occurs.
 */
String readUTF() throws IOException ;

Fixed version (ground truth):
/** 
 * Reads in a string that has been encoded using a <a href="../../../java/io/DataInput.html#modified-utf-8">modified UTF-8</a> format.  The general contract of <code>readUTF</code> is that it reads a representation of a Unicode character string encoded in modified UTF-8 format; this string of characters is then returned as a <code>String</code>. <p> First, two bytes are read and used to construct an unsigned 16-bit integer in the manner of the <code>readUnsignedShort</code> method, using network byte order (regardless of the current byte order setting). This integer value is called the <i>UTF length</i> and specifies the number of additional bytes to be read. These bytes are then converted to characters by considering them in groups. The length of each group is computed from the value of the first byte of the group. The byte following a group, if any, is the first byte of the next group. <p> If the first byte of a group matches the bit pattern <code>0xxxxxxx</code> (where <code>x</code> means "may be <code>0</code> or <code>1</code>"), then the group consists of just that byte. The byte is zero-extended to form a character. <p> If the first byte of a group matches the bit pattern <code>110xxxxx</code>, then the group consists of that byte <code>a</code> and a second byte <code>b</code>. If there is no byte <code>b</code> (because byte <code>a</code> was the last of the bytes to be read), or if byte <code>b</code> does not match the bit pattern <code>10xxxxxx</code>, then a <code>UTFDataFormatException</code> is thrown. Otherwise, the group is converted to the character: <pre><code> (char)(((a&amp; 0x1F) &lt;&lt; 6) | (b &amp; 0x3F)) </code></pre> If the first byte of a group matches the bit pattern <code>1110xxxx</code>, then the group consists of that byte <code>a</code> and two more bytes <code>b</code> and <code>c</code>.  If there is no byte <code>c</code> (because byte <code>a</code> was one of the last two of the bytes to be read), or either byte <code>b</code> or byte <code>c</code> does not match the bit pattern <code>10xxxxxx</code>, then a <code>UTFDataFormatException</code> is thrown. Otherwise, the group is converted to the character: <pre><code> (char)(((a &amp; 0x0F) &lt;&lt; 12) | ((b &amp; 0x3F) &lt;&lt; 6) | (c &amp; 0x3F)) </code></pre> If the first byte of a group matches the pattern <code>1111xxxx</code> or the pattern <code>10xxxxxx</code>, then a <code>UTFDataFormatException</code> is thrown. <p> If end of file is encountered at any time during this entire process, then an <code>java.io.EOFException</code> is thrown. <p> After every group has been converted to a character by this process, the characters are gathered, in the same order in which their corresponding groups were read from the input stream, to form a <code>String</code>, which is returned. <p> The current byte order setting is ignored. <p> The bit offset within the stream is reset to zero before the read occurs. <p><strong>Note:</strong> This method should not be used in the  implementation of image formats that use standard UTF-8, because  the modified UTF-8 used here is incompatible with standard UTF-8.
 * @return a String read from the stream.
 * @exception java.io.EOFException  if this stream reaches the endbefore reading all the bytes.
 * @exception java.io.UTFDataFormatException if the bytes do not representa valid modified UTF-8 encoding of a string.
 * @exception IOException if an I/O error occurs.
 */
String readUTF() throws IOException ;