Buggy code:
private static final String UTF_32BE = "UTF-32BE" ; private static final String UTF_32LE = "UTF-32LE" ; private static final String UTF_16 = "UTF-16" ; private static final String UTF_32 = "UTF-32" ; private static final String EBCDIC = "CP1047" ; private static final ByteOrderMark [ ] BOMS = new ByteOrderMark [ ] { ByteOrderMark . UTF_8 , ByteOrderMark . UTF_16BE , ByteOrderMark . UTF_16LE , ByteOrderMark . UTF_32BE , ByteOrderMark . UTF_32LE } ; private static final ByteOrderMark [ ] XML_GUESS_BYTES = new ByteOrderMark [ ] { new ByteOrderMark ( XmlStreamReader . UTF_8 , 60 , 63 , 120 , 109 ) , new ByteOrderMark ( XmlStreamReader . UTF_16BE , 0 , 60 , 0 , 63 ) , new ByteOrderMark ( XmlStreamReader . UTF_16LE , 60 , 0 , 63 , 0 ) , new ByteOrderMark ( XmlStreamReader . UTF_32BE , 0 , 0 , 0 , 60 , 0 , 0 , 0 , 63 , 0 , 0 , 0 , 120 , 0 , 0 , 0 , 109 ) , new ByteOrderMark ( XmlStreamReader . UTF_32LE , 60 , 0 , 0 , 0 , 63 , 0 , 0 , 0 , 120 , 0 , 0 , 0 , 109 , 0 , 0 , 0 ) , new ByteOrderMark ( XmlStreamReader . EBCDIC , 76 , 111 , 167 , 148 ) } ; private final Reader reader ; private final String encoding ; private final String defaultEncoding ; public String getDefaultEncoding ( ) { } public XmlStreamReader ( final File file ) throws IOException { } public XmlStreamReader ( final InputStream is ) throws IOException { } public XmlStreamReader ( final InputStream is , final boolean lenient ) throws IOException { } public XmlStreamReader ( final InputStream is , final boolean lenient , final String defaultEncoding ) throws IOException { } public XmlStreamReader ( final URL url ) throws IOException { } public XmlStreamReader ( final URLConnection conn , final String defaultEncoding ) throws IOException { } public XmlStreamReader ( final InputStream is , final String httpContentType ) throws IOException { } public XmlStreamReader ( final InputStream is , final String httpContentType , final boolean lenient , final String defaultEncoding ) throws IOException { } public XmlStreamReader ( final InputStream is , final String httpContentType , final boolean lenient ) throws IOException { } public String getEncoding ( ) { } @ Override public int read ( final char [ ] buf , final int offset , final int len ) throws IOException { } @ Override public void close ( ) throws IOException { } private String doRawStream ( final BOMInputStream bom , final BOMInputStream pis , final boolean lenient ) throws IOException { } private String doHttpStream ( final BOMInputStream bom , final BOMInputStream pis , final String httpContentType , final boolean lenient ) throws IOException { } private String doLenientDetection ( String httpContentType , XmlStreamReaderException ex ) throws IOException { } String calculateRawEncoding ( final String bomEnc , final String xmlGuessEnc , final String xmlEnc ) throws IOException { } String calculateHttpEncoding ( final String httpContentType , final String bomEnc , final String xmlGuessEnc , final String xmlEnc , final boolean lenient ) throws IOException { } static String getContentTypeMime ( final String httpContentType ) { } private static final Pattern CHARSET_PATTERN = Pattern . compile ( "charset=[\"\']?([.[^;<seq2seq4repair_space>\"\']]*)[\"\']?" ) ; static String getContentTypeEncoding ( final String httpContentType ) { } public static final Pattern ENCODING_PATTERN = Pattern . compile ( "<\\?xml.*encoding[\\s]*=[\\s]*((?:\".[^\"]*\")|(?:\'.[^\']*\'))" , Pattern . MULTILINE ) ; private static String getXmlProlog ( final InputStream is , final String guessedEnc ) throws IOException { String encoding = null ; if ( guessedEnc != null ) { final byte [ ] bytes = new byte [ XmlStreamReader . BUFFER_SIZE ] ; is . mark ( XmlStreamReader . BUFFER_SIZE ) ; int offset = 0 ; int max = XmlStreamReader . BUFFER_SIZE ; int c = is . read ( bytes , offset , max ) ; int firstGT = - 1 ; <START_BUG> String xmlProlog = null ; <END_BUG> while ( ( ( c != ( - 1 ) ) && ( firstGT == ( - 1 ) ) ) && ( offset < ( XmlStreamReader . BUFFER_SIZE ) ) ) { offset += c ; max -= c ; c = is . read ( bytes , offset , max ) ; xmlProlog = new String ( bytes , 0 , offset , guessedEnc ) ; firstGT = xmlProlog . indexOf ( '>' ) ; } if ( firstGT == ( - 1 ) ) { if ( c == ( - 1 ) ) { throw new IOException ( "Unexpected<seq2seq4repair_space>end<seq2seq4repair_space>of<seq2seq4repair_space>XML<seq2seq4repair_space>stream" ) ; } else { throw new IOException ( ( ( "XML<seq2seq4repair_space>prolog<seq2seq4repair_space>or<seq2seq4repair_space>ROOT<seq2seq4repair_space>element<seq2seq4repair_space>not<seq2seq4repair_space>found<seq2seq4repair_space>on<seq2seq4repair_space>first<seq2seq4repair_space>" + offset ) + "<seq2seq4repair_space>bytes" ) ) ; } } final int bytesRead = offset ; if ( bytesRead > 0 ) { is . reset ( ) ; final BufferedReader bReader = new BufferedReader ( new StringReader ( xmlProlog . substring ( 0 , ( firstGT + 1 ) ) ) ) ; final StringBuffer prolog = new StringBuffer ( ) ; String line = bReader . readLine ( ) ; while ( line != null ) { prolog . append ( line ) ; line = bReader . readLine ( ) ; } final Matcher m = XmlStreamReader . ENCODING_PATTERN . matcher ( prolog ) ; if ( m . find ( ) ) { encoding = m . group ( 1 ) . toUpperCase ( ) ; encoding = encoding . substring ( 1 , ( ( encoding . length ( ) ) - 1 ) ) ; } } } return encoding ; } static boolean isAppXml ( final String mime ) { } static boolean isTextXml ( final String mime ) { } private static final String RAW_EX_1 = "Invalid<seq2seq4repair_space>encoding,<seq2seq4repair_space>BOM<seq2seq4repair_space>[{0}]<seq2seq4repair_space>XML<seq2seq4repair_space>guess<seq2seq4repair_space>[{1}]<seq2seq4repair_space>XML<seq2seq4repair_space>prolog<seq2seq4repair_space>[{2}]<seq2seq4repair_space>encoding<seq2seq4repair_space>mismatch" ; private static final String RAW_EX_2 = "Invalid<seq2seq4repair_space>encoding,<seq2seq4repair_space>BOM<seq2seq4repair_space>[{0}]<seq2seq4repair_space>XML<seq2seq4repair_space>guess<seq2seq4repair_space>[{1}]<seq2seq4repair_space>XML<seq2seq4repair_space>prolog<seq2seq4repair_space>[{2}]<seq2seq4repair_space>unknown<seq2seq4repair_space>BOM" ; private static final String HTTP_EX_1 = "Invalid<seq2seq4repair_space>encoding,<seq2seq4repair_space>CT-MIME<seq2seq4repair_space>[{0}]<seq2seq4repair_space>CT-Enc<seq2seq4repair_space>[{1}]<seq2seq4repair_space>BOM<seq2seq4repair_space>[{2}]<seq2seq4repair_space>XML<seq2seq4repair_space>guess<seq2seq4repair_space>[{3}]<seq2seq4repair_space>XML<seq2seq4repair_space>prolog<seq2seq4repair_space>[{4}],<seq2seq4repair_space>BOM<seq2seq4repair_space>must<seq2seq4repair_space>be<seq2seq4repair_space>NULL" ; private static final String HTTP_EX_2 = "Invalid<seq2seq4repair_space>encoding,<seq2seq4repair_space>CT-MIME<seq2seq4repair_space>[{0}]<seq2seq4repair_space>CT-Enc<seq2seq4repair_space>[{1}]<seq2seq4repair_space>BOM<seq2seq4repair_space>[{2}]<seq2seq4repair_space>XML<seq2seq4repair_space>guess<seq2seq4repair_space>[{3}]<seq2seq4repair_space>XML<seq2seq4repair_space>prolog<seq2seq4repair_space>[{4}],<seq2seq4repair_space>encoding<seq2seq4repair_space>mismatch" ; private static final String HTTP_EX_3 = "Invalid<seq2seq4repair_space>encoding,<seq2seq4repair_space>CT-MIME<seq2seq4repair_space>[{0}]<seq2seq4repair_space>CT-Enc<seq2seq4repair_space>[{1}]<seq2seq4repair_space>BOM<seq2seq4repair_space>[{2}]<seq2seq4repair_space>XML<seq2seq4repair_space>guess<seq2seq4repair_space>[{3}]<seq2seq4repair_space>XML<seq2seq4repair_space>prolog<seq2seq4repair_space>[{4}],<seq2seq4repair_space>Invalid<seq2seq4repair_space>MIME"

Fix:
String xmlProlog = "" ;