Buggy code:
public class ListNotesTableFactory extends AbstractTableFactory { private static final Logger LOG = LoggerFactory . getLogger ( ListNotesTableFactory . class . getName ( ) ) ; private AuditUserLoginDao auditUserLoginDao ; private StudySubjectDAO studySubjectDao ; private UserAccountDAO userAccountDao ; private DiscrepancyNoteDAO discrepancyNoteDao ; private StudyDAO studyDao ; private SubjectDAO subjectDao ; private CRFVersionDAO crfVersionDao ; private CRFDAO crfDao ; private StudyEventDAO studyEventDao ; private StudyEventDefinitionDAO studyEventDefinitionDao ; private EventDefinitionCRFDAO eventDefinitionCRFDao ; private ItemDataDAO itemDataDao ; private ItemDAO itemDao ; private EventCRFDAO eventCRFDao ; private StudyBean currentStudy ; private ResourceBundle resword ; private ResourceBundle resformat ; private List < DiscrepancyNoteBean > allNotes = new ArrayList < DiscrepancyNoteBean > ( ) ; private ArrayList < StudyEventDefinitionBean > studyEventDefinitions ; private String module ; private Integer resolutionStatus ; private Integer discNoteType ; private Boolean studyHasDiscNotes = new Boolean ( false ) ; private ViewNotesService viewNotesService ; private final boolean showMoreLink ; private DiscrepancyNotesSummary notesSummary ; private final ListNotesTableFactory . TypeDroplistFilterEditor discrepancyNoteTypeDropdown = new ListNotesTableFactory . TypeDroplistFilterEditor ( ) ; private final ListNotesTableFactory . ResolutionStatusDroplistFilterEditor resolutionStatusDropdown = new ListNotesTableFactory . ResolutionStatusDroplistFilterEditor ( ) ; public ListNotesTableFactory ( boolean showMoreLink ) { } @ Override protected String getTableName ( ) { } @ Override protected void configureColumns ( TableFacade tableFacade , Locale locale ) { } @ Override public void configureTableFacadePostColumnConfiguration ( TableFacade tableFacade ) { } public List < DiscrepancyNoteBean > findAllNotes ( TableFacade tableFacade ) { } @ Override public void setDataAndLimitVariables ( TableFacade tableFacade ) { resword = ResourceBundleProvider . getWordsBundle ( getLocale ( ) ) ; resformat = ResourceBundleProvider . getFormatBundle ( getLocale ( ) ) ; Limit limit = tableFacade . getLimit ( ) ; if ( ! ( limit . isComplete ( ) ) ) { int totalRows = getDiscrepancyNoteDao ( ) . getCountWithFilter ( getListNoteFilter ( limit ) , currentStudy ) ; tableFacade . setTotalRows ( totalRows ) ; } ViewNotesFilterCriteria filter = ViewNotesFilterCriteria . buildFilterCriteria ( limit , getDateFormat ( ) , discrepancyNoteTypeDropdown . getDecoder ( ) , resolutionStatusDropdown . getDecoder ( ) ) ; notesSummary = getViewNotesService ( ) . calculateNotesSummary ( getCurrentStudy ( ) , filter ) ; int pageSize = limit . getRowSelect ( ) . getMaxRows ( ) ; int firstRecordShown = ( ( limit . getRowSelect ( ) . getPage ( ) ) - 1 ) * pageSize ; <START_BUG> if ( firstRecordShown > ( notesSummary . getTotal ( ) ) ) { <END_BUG> limit . getRowSelect ( ) . setPage ( ( ( int ) ( Math . ceil ( ( ( ( double ) ( notesSummary . getTotal ( ) ) ) // pageSize ) ) ) ) ) ; filter = ViewNotesFilterCriteria . buildFilterCriteria ( limit , getDateFormat ( ) , discrepancyNoteTypeDropdown . getDecoder ( ) , resolutionStatusDropdown . getDecoder ( ) ) ; } List < DiscrepancyNoteBean > items = getViewNotesService ( ) . listNotes ( getCurrentStudy ( ) , filter , ViewNotesSortCriteria . buildFilterCriteria ( limit . getSortSet ( ) ) ) ; this . setAllNotes ( items ) ; Collection < HashMap < Object , Object > > theItems = new ArrayList < HashMap < Object , Object > > ( ) ; for ( DiscrepancyNoteBean discrepancyNoteBean : items ) { HashMap < Object , Object > h = new HashMap < Object , Object > ( ) ; h . put ( "studySubject" , discrepancyNoteBean . getStudySub ( ) ) ; h . put ( "studySubject.label" , discrepancyNoteBean . getStudySub ( ) . getLabel ( ) ) ; h . put ( "discrepancyNoteBean.disType" , discrepancyNoteBean . getDisType ( ) ) ; h . put ( "discrepancyNoteBean.resolutionStatus" , discrepancyNoteBean . getResStatus ( ) ) ; h . put ( "age" , discrepancyNoteBean . getAge ( ) ) ; h . put ( "days" , discrepancyNoteBean . getDays ( ) ) ; h . put ( "siteId" , discrepancyNoteBean . getSiteId ( ) ) ; h . put ( "discrepancyNoteBean" , discrepancyNoteBean ) ; h . put ( "discrepancyNoteBean.createdDate" , discrepancyNoteBean . getCreatedDate ( ) ) ; h . put ( "discrepancyNoteBean.updatedDate" , discrepancyNoteBean . getUpdatedDate ( ) ) ; h . put ( "eventName" , discrepancyNoteBean . getEventName ( ) ) ; h . put ( "eventStartDate" , discrepancyNoteBean . getEventStart ( ) ) ; h . put ( "crfName" , discrepancyNoteBean . getCrfName ( ) ) ; h . put ( "crfStatus" , discrepancyNoteBean . getCrfStatus ( ) ) ; h . put ( "entityName" , discrepancyNoteBean . getEntityName ( ) ) ; h . put ( "entityValue" , discrepancyNoteBean . getEntityValue ( ) ) ; h . put ( "discrepancyNoteBean" , discrepancyNoteBean ) ; h . put ( "discrepancyNoteBean.description" , discrepancyNoteBean . getDescription ( ) ) ; h . put ( "discrepancyNoteBean.detailedNotes" , discrepancyNoteBean . getDetailedNotes ( ) ) ; h . put ( "numberOfNotes" , discrepancyNoteBean . getNumChildren ( ) ) ; h . put ( "discrepancyNoteBean.user" , discrepancyNoteBean . getAssignedUser ( ) ) ; h . put ( "discrepancyNoteBean.entityType" , discrepancyNoteBean . getEntityType ( ) ) ; h . put ( "discrepancyNoteBean.owner" , discrepancyNoteBean . getOwner ( ) ) ; theItems . add ( h ) ; setStudyHasDiscNotes ( true ) ; } tableFacade . setItems ( theItems ) ; } @ Override public TableFacade getTableFacadeImpl ( HttpServletRequest request , HttpServletResponse response ) { } public ListNotesFilter getListNoteFilter ( Limit limit ) { } protected ListNotesSort getListSubjectSort ( Limit limit ) { } public AuditUserLoginDao getAuditUserLoginDao ( ) { } public void setAuditUserLoginDao ( AuditUserLoginDao auditUserLoginDao ) { } private class ResolutionStatusDroplistFilterEditor extends DropdownFilter { public ResolutionStatusDroplistFilterEditor ( ) { } } private class TypeDroplistFilterEditor extends DropdownFilter { public TypeDroplistFilterEditor ( ) { } } private class ResolutionStatusCellEditor implements CellEditor { @ Override @ SuppressWarnings ( "unchecked" ) public Object getValue ( Object item , String property , int rowcount ) { } } private class DiscrepancyNoteTypeCellEditor implements CellEditor { @ Override @ SuppressWarnings ( "unchecked" ) public Object getValue ( Object item , String property , int rowcount ) { } }

Fix:
if ( ( firstRecordShown > ( notesSummary . getTotal ( ) ) ) && ( ( notesSummary . getTotal ( ) ) != 0 ) ) {