Buggy code:
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 ) { } private List userIdList ; private List userSearchCriteriaList ; public void addUserCriteria ( String userId , String searchCriteria ) { } 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 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 void addUserCriteria ( Criteria crit ) { } public void addUserCriteria ( String userId , String attrId , boolean isAnyCreatedBy , boolean isAnyUserAttr , Criteria crit ) { } private Criterion getUserCriterion ( Criteria crit , String userId , boolean isAnyCreatedBy ) { } private NumberKey [ ] getTextMatches ( List attValues ) throws Exception { } private void addStateChangeQuery ( Criteria crit ) throws Exception { } private NumberKey [ ] addCoreSearchCriteria ( Criteria crit ) throws Exception { } private void addIssuePKsCriteria ( Criteria crit , NumberKey [ ] ids ) { } public List getMatchingIssues ( ) throws Exception { } public int getIssueCount ( ) throws Exception { } private List sortIssues ( Criteria crit ) throws Exception { } private List sortByUniqueId ( Criteria crit ) throws Exception { } private List sortByAttribute ( Criteria crit ) throws Exception { Vector attSet = new Vector ( ) ; Vector attNotSet = new Vector ( ) ; List unSortedIssues = IssuePeer . doSelect ( crit ) ; List sortedIssues = new ArrayList ( unSortedIssues . size ( ) ) ; NumberKey sortAttrId = getSortAttributeId ( ) ; Attribute att = AttributeManager . getInstance ( sortAttrId ) ; for ( int j = 0 ; j < ( unSortedIssues . size ( ) ) ; j ++ ) { Issue issue = ( ( Issue ) ( unSortedIssues . get ( j ) ) ) ; AttributeValue sortAttVal = ( ( AttributeValue ) ( issue . getModuleAttributeValuesMap ( ) . get ( att . getName ( ) . toUpperCase ( ) ) ) ) ; Object sortValue = null ; if ( sortAttVal instanceof OptionAttribute ) { sortValue = sortAttVal . getAttributeOption ( ) ; } else { sortValue = sortAttVal . getValue ( ) ; } if ( sortValue == null ) { attNotSet . add ( issue ) ; } else { attSet . add ( issue . getIssueId ( ) ) ; } } if ( ( attSet . size ( ) ) > 0 ) { String sortColumn = null ; Criteria crit2 = new Criteria ( ) ; if ( att . isOptionAttribute ( ) ) { crit2 . addIn ( ISSUE_ID , attSet ) ; crit2 . add ( AttributeOptionPeer . ATTRIBUTE_ID , sortAttrId ) ; crit2 . addJoin ( AttributeOptionPeer . OPTION_ID , RModuleOptionPeer . OPTION_ID ) ; crit2 . addJoin ( OPTION_ID , RModuleOptionPeer . OPTION_ID ) ; crit2 . addJoin ( ISSUE_ID , IssuePeer . ISSUE_ID ) ; crit2 . addJoin ( MODULE_ID , RModuleOptionPeer . MODULE_ID ) ; crit2 . addJoin ( IssuePeer . TYPE_ID , ISSUE_TYPE_ID ) ; <START_BUG> sortColumn = RModuleOptionPeer . WEIGHT ; <END_BUG> crit2 . setDistinct ( ) ; } else { crit2 . addIn ( ISSUE_ID , attSet ) ; crit2 . add ( AttributeValuePeer . ATTRIBUTE_ID , sortAttrId ) ; crit2 . addJoin ( ISSUE_ID , IssuePeer . ISSUE_ID ) ; crit2 . setDistinct ( ) ; sortColumn = AttributeValuePeer . VALUE ; } if ( getSortPolarity ( ) . equals ( "desc" ) ) { crit2 . addDescendingOrderByColumn ( sortColumn ) ; } else { crit2 . addAscendingOrderByColumn ( sortColumn ) ; } sortedIssues . addAll ( IssuePeer . doSelect ( crit2 ) ) ; } sortedIssues . addAll ( attNotSet ) ; return sortedIssues ; } }

Fix:
sortColumn = RModuleOptionPeer . PREFERRED_ORDER ;