Buggy code:
public class SimpleResolver implements Resolver { public static final int DEFAULT_PORT = 53 ; private InetAddress addr ; private int port = SimpleResolver . DEFAULT_PORT ; private boolean useTCP ; private boolean ignoreTruncation ; private byte EDNSlevel = - 1 ; private TSIG tsig ; private int timeoutValue = 10 * 1000 ; private static final short DEFAULT_UDPSIZE = 512 ; private static final short EDNS_UDPSIZE = 1280 ; private static String defaultResolver = "localhost" ; private static int uniqueID = 0 ; public SimpleResolver ( String hostname ) throws UnknownHostException { } public SimpleResolver ( ) throws UnknownHostException { } public static void setDefaultResolver ( String hostname ) { } public void setPort ( int port ) { } public void setTCP ( boolean flag ) { } public void setIgnoreTruncation ( boolean flag ) { } public void setEDNS ( int level ) { } public void setTSIGKey ( TSIG key ) { } public void setTSIGKey ( Name name , byte [ ] key ) { } public void setTSIGKey ( String name , String key ) { } public void setTSIGKey ( String key ) throws UnknownHostException { } public void setTimeout ( int secs ) { } private byte [ ] readUDP ( DatagramSocket s , int max ) throws IOException { } private void writeUDP ( DatagramSocket s , byte [ ] out , InetAddress addr , int port ) throws IOException { } private byte [ ] readTCP ( Socket s ) throws IOException { } private void writeTCP ( Socket s , byte [ ] out ) throws IOException { } private Message parseMessage ( byte [ ] b ) throws WireParseException { } private void verifyTSIG ( Message query , Message response , byte [ ] b , TSIG tsig ) { } private void applyEDNS ( Message query ) { } private int maxUDPSize ( Message query ) { } public Message send ( Message query ) throws IOException { if ( Options . check ( "verbose" ) ) System . err . println ( ( ( ( "Sending<seq2seq4repair_space>to<seq2seq4repair_space>" + ( addr . getHostAddress ( ) ) ) + ":" ) + ( port ) ) ) ; if ( ( query . getHeader ( ) . getOpcode ( ) ) == ( Opcode . QUERY ) ) { Record question = query . getQuestion ( ) ; if ( ( question != null ) && ( ( question . getType ( ) ) == ( Type . AXFR ) ) ) return sendAXFR ( query ) ; } query = ( ( Message ) ( query . clone ( ) ) ) ; applyEDNS ( query ) ; if ( ( tsig ) != null ) tsig . apply ( query , null ) ; byte [ ] out = query . toWire ( MAXLENGTH ) ; int udpSize = maxUDPSize ( query ) ; boolean tcp = false ; do { byte [ ] in ; if ( ( useTCP ) || ( ( out . length ) > udpSize ) ) tcp = true ; if ( tcp ) { Socket s = new Socket ( addr , port ) ; s . setSoTimeout ( timeoutValue ) ; try { writeTCP ( s , out ) ; in = readTCP ( s ) ; } finally { s . close ( ) ; } } else { DatagramSocket s = new DatagramSocket ( ) ; s . setSoTimeout ( timeoutValue ) ; try { writeUDP ( s , out , addr , port ) ; in = readUDP ( s , udpSize ) ; } finally { s . close ( ) ; } } if ( ( in . length ) < ( Header . LENGTH ) ) { throw new WireParseException ( ( "invalid<seq2seq4repair_space>DNS<seq2seq4repair_space>header<seq2seq4repair_space>-<seq2seq4repair_space>" + "too<seq2seq4repair_space>short" ) ) ; } <START_BUG> int id = ( ( ( in [ 0 ] ) & 255 ) << 8 ) + ( in [ 1 ] ) ; <END_BUG> int qid = query . getHeader ( ) . getID ( ) ; if ( id != qid ) { if ( Options . check ( "verbose" ) ) { System . err . println ( ( ( ( "expected<seq2seq4repair_space>id<seq2seq4repair_space>" + qid ) + ";<seq2seq4repair_space>got<seq2seq4repair_space>id<seq2seq4repair_space>" ) + id ) ) ; } continue ; } Message response = parseMessage ( in ) ; verifyTSIG ( query , response , in , tsig ) ; if ( ( ( ! tcp ) && ( ! ( ignoreTruncation ) ) ) && ( response . getHeader ( ) . getFlag ( TC ) ) ) tcp = true ; else return response ; } while ( true ) ; } public Object sendAsync ( final Message query , final ResolverListener listener ) { } private Message sendAXFR ( Message query ) throws IOException { } static class Stream { SimpleResolver res ; Socket sock ; TSIG tsig ; StreamVerifier verifier ; Stream ( SimpleResolver res ) throws IOException { } void send ( Message query ) throws IOException { if ( ( tsig ) != null ) { tsig . apply ( query , null ) ; verifier = new TSIG . StreamVerifier ( tsig , query . getTSIG ( ) ) ; } byte [ ] out = query . toWire ( MAXLENGTH ) ; res . writeTCP ( sock , out ) ; } Message next ( ) throws IOException { } void close ( ) { } } }

Fix:
int id = ( ( ( in [ 0 ] ) & 255 ) << 8 ) + ( ( in [ 1 ] ) & 255 ) ;