Buggy code:
public class IssueSearch extends Issue { public static final String ASC = "asc" ; public static final String DESC = "desc" ; private static final NumberKey ALL_TEXT = new NumberKey ( "0" ) ; private static final String PARENT_ID ; private static final String CHILD_ID ; private static final String AV_ISSUE_ID ; private static final String AV_OPTION_ID ; private static final String AV_USER_ID ; private SimpleDateFormat formatter ; private String searchWords ; private NumberKey [ ] textScope ; private String minId ; private String maxId ; private String minDate ; private String maxDate ; private int minVotes ; private NumberKey stateChangeAttributeId ; private NumberKey stateChangeFromOptionId ; private NumberKey stateChangeToOptionId ; private String stateChangeFromDate ; private String stateChangeToDate ; private NumberKey [ ] issueIdsFromTextSearch ; private List issueIdsFromUserSearch ; private NumberKey sortAttributeId ; private String sortPolarity ; public IssueSearch ( Issue issue ) throws Exception { } public IssueSearch ( Module module , IssueType issueType ) throws Exception { } public String getSearchWords ( ) { } public void setSearchWords ( String v ) { } public void setIssueIdsFromUserSearch ( List l ) { } public List getIssueIdsFromUserSearch ( ) { } public void setIssueIdsFromTextSearch ( NumberKey [ ] n ) { } public NumberKey [ ] getIssueIdsFromTextSearch ( ) { } public NumberKey [ ] getTextScope ( ) throws Exception { } private void setTextScopeToAll ( ) throws Exception { } public void setTextScope ( NumberKey [ ] v ) { } public String getMinId ( ) { } public void setMinId ( String v ) { } public String getMaxId ( ) { } public void setMaxId ( String v ) { } public String getMinDate ( ) { } public void setMinDate ( String v ) { } public String getMaxDate ( ) { } public void setMaxDate ( String v ) { } public int getMinVotes ( ) { } public void setMinVotes ( int v ) { } public NumberKey getStateChangeAttributeId ( ) { } public void setStateChangeAttributeId ( NumberKey v ) { } public NumberKey getStateChangeFromOptionId ( ) { } public void setStateChangeFromOptionId ( NumberKey v ) { } public NumberKey getStateChangeToOptionId ( ) { } public void setStateChangeToOptionId ( NumberKey v ) { } public String getStateChangeFromDate ( ) { } public void setStateChangeFromDate ( String v ) { } public String getStateChangeToDate ( ) { } public void setStateChangeToDate ( String v ) { } public NumberKey getSortAttributeId ( ) { } public void setSortAttributeId ( NumberKey v ) { } public String getSortPolarity ( ) { } public void setSortPolarity ( String v ) { } public NumberKey getALL_TEXT ( ) { } public List getQuickSearchTextAttributeValues ( ) throws Exception { } public List getTextAttributeValues ( ) throws Exception { } private List getTextAttributeValues ( boolean quickSearchOnly ) throws Exception { } public List getQuickSearchOptionAttributeValues ( ) throws Exception { } public List getOptionAttributeValues ( ) throws Exception { } private List getOptionAttributeValues ( boolean quickSearchOnly ) throws Exception { } private void removeUnsetValues ( List attValues ) { } private void addMinimumVotes ( Criteria crit ) throws ScarabException { } private void addIssueIdRange ( Criteria crit ) throws Exception , ScarabException { } private void combineUserAndTextCriteria ( Criteria crit ) throws ScarabException { } private void setDefaults ( FederatedId minFid , FederatedId maxFid ) throws Exception { } private void addCreatedDateRange ( Criteria crit ) throws Exception , ScarabException { } public Date parseDate ( String dateString , boolean addTwentyFourHours ) throws ParseException { } private Date parseDate ( String s , String [ ] patterns ) throws ParseException { } private void addDateRange ( String column , Date minUtilDate , Date maxUtilDate , Criteria crit ) throws ScarabException { } private void addSelectedAttributes ( Criteria crit , List attValues ) throws Exception { } private Criterion buildOptionCriterion ( AttributeValue aval ) throws Exception { } private NumberKey [ ] addTextMatches ( Criteria crit , List attValues ) throws Exception { } private void addStateChangeQuery ( Criteria crit ) throws Exception { } public List getMatchingIssues ( ) throws Exception { Criteria crit = new Criteria ( ) ; crit . add ( MODULE_ID , getModule ( ) . getModuleId ( ) ) ; crit . add ( TYPE_ID , getIssueType ( ) . getIssueTypeId ( ) ) ; crit . add ( DELETED , false ) ; Criteria tempCrit = new Criteria ( 2 ) . add ( AttributeValuePeer . DELETED , false ) ; List attValues = getAttributeValues ( tempCrit ) ; removeUnsetValues ( attValues ) ; addSelectedAttributes ( crit , attValues ) ; NumberKey [ ] matchingIssueIds = addTextMatches ( crit , attValues ) ; List sortedIssues = null ; if ( ( matchingIssueIds == null ) || ( ( matchingIssueIds . length ) > 0 ) ) { addIssueIdRange ( crit ) ; addCreatedDateRange ( crit ) ; addMinimumVotes ( crit ) ; combineUserAndTextCriteria ( crit ) ; addStateChangeQuery ( crit ) ; sortedIssues = sortIssues ( crit ) ; } else { sortedIssues = new ArrayList ( 0 ) ; } List sortedIssueIds = new ArrayList ( ) ; for ( int i = 0 ; i < ( sortedIssues . size ( ) ) ; i ++ ) { <START_BUG> sortedIssueIds . add ( ( ( Issue ) ( sortedIssues . get ( i ) ) ) . getIssueId ( ) ) ; <END_BUG> } return sortedIssueIds ; } private List sortIssues ( Criteria crit ) throws Exception { } private List sortByUniqueId ( Criteria crit ) throws Exception { } private List sortByAttribute ( Criteria crit ) throws Exception { } }

Fix:
sortedIssueIds . add ( ( ( Issue ) ( sortedIssues . get ( i ) ) ) . getUniqueId ( ) ) ;