Buggy code:
public class Cache extends NameSet { private class Element { RRset rrset ; byte credibility ; long timeIn ; int ttl ; int srcid ; public Element ( int _ttl , byte cred , int src ) { } public Element ( Record r , byte cred , int src ) { } public Element ( RRset r , byte cred , int src ) { } public void update ( Record r ) { } public boolean expiredTTL ( ) { } public String toString ( ) { } } public Cache ( ) { } public Cache ( String file ) throws IOException { } public void addRecord ( Record r , byte cred , Object o ) { } public void addRRset ( RRset rrset , byte cred , Object o ) { } public void addNegative ( Name name , short type , short dclass , int ttl , byte cred , Object o ) { } public SetResponse lookupRecords ( Name name , short type , short dclass , byte minCred ) { } private RRset [ ] findRecords ( Name name , short type , short dclass , byte minCred ) { } public RRset [ ] findRecords ( Name name , short type , short dclass ) { } public RRset [ ] findAnyRecords ( Name name , short type , short dclass ) { } public void addMessage ( Message in ) { Enumeration e ; boolean isAuth = in . getHeader ( ) . getFlag ( AA ) ; Name queryName = in . getQuestion ( ) . getName ( ) ; short queryType = in . getQuestion ( ) . getType ( ) ; short queryClass = in . getQuestion ( ) . getDClass ( ) ; byte cred ; short rcode = in . getHeader ( ) . getRcode ( ) ; <START_BUG> short ancount = in . getHeader ( ) . getCount ( ANSWER ) ; <END_BUG> if ( ( rcode != ( Rcode . NOERROR ) ) && ( rcode != ( Rcode . NXDOMAIN ) ) ) return ; e = in . getSection ( ANSWER ) ; while ( e . hasMoreElements ( ) ) { Record r = ( ( Record ) ( e . nextElement ( ) ) ) ; if ( isAuth && ( r . getName ( ) . equals ( queryName ) ) ) cred = Credibility . AUTH_ANSWER ; else if ( isAuth ) cred = Credibility . AUTH_NONAUTH_ANSWER ; else cred = Credibility . NONAUTH_ANSWER ; addRecord ( r , cred , in ) ; } if ( ( ancount == 0 ) || ( rcode == ( Rcode . NXDOMAIN ) ) ) { SOARecord soa = null ; e = in . getSection ( AUTHORITY ) ; while ( e . hasMoreElements ( ) ) { Record r = ( ( Record ) ( e . nextElement ( ) ) ) ; if ( ( r . getType ( ) ) == ( Type . SOA ) ) { soa = ( ( SOARecord ) ( r ) ) ; break ; } } if ( isAuth ) cred = Credibility . AUTH_AUTHORITY ; else cred = Credibility . NONAUTH_AUTHORITY ; if ( soa != null ) { int ttl = Math . min ( soa . getTTL ( ) , soa . getMinimum ( ) ) ; if ( ancount == 0 ) addNegative ( queryName , queryType , queryClass , ttl , cred , in ) ; else { Record [ ] cnames ; cnames = in . getSectionArray ( ANSWER ) ; int last = ( cnames . length ) - 1 ; Name cname ; cname = ( ( CNAMERecord ) ( cnames [ last ] ) ) . getTarget ( ) ; addNegative ( cname , queryType , queryClass , ttl , cred , in ) ; } } } e = in . getSection ( AUTHORITY ) ; while ( e . hasMoreElements ( ) ) { Record r = ( ( Record ) ( e . nextElement ( ) ) ) ; if ( isAuth ) cred = Credibility . AUTH_AUTHORITY ; else cred = Credibility . NONAUTH_AUTHORITY ; addRecord ( r , cred , in ) ; } e = in . getSection ( ADDITIONAL ) ; while ( e . hasMoreElements ( ) ) { Record r = ( ( Record ) ( e . nextElement ( ) ) ) ; if ( isAuth ) cred = Credibility . AUTH_ADDITIONAL ; else cred = Credibility . NONAUTH_ADDITIONAL ; addRecord ( r , cred , in ) ; } } }

Fix:
int ancount = in . getHeader ( ) . getCount ( ANSWER ) ;