Buggy code:
return Collections . emptyList ( ) ; } if ( ! ( isConnected ( ) ) ) { InfluxDBPersistenceService . logger . error ( "InfluxDB<seq2seq4repair_space>is<seq2seq4repair_space>not<seq2seq4repair_space>yet<seq2seq4repair_space>connected" ) ; return Collections . emptyList ( ) ; } List < HistoricItem > historicItems = new ArrayList < HistoricItem > ( ) ; StringBuffer query = new StringBuffer ( ) ; query . append ( "select<seq2seq4repair_space>" ) ; query . append ( InfluxDBPersistenceService . VALUE_COLUMN_NAME ) ; query . append ( ",<seq2seq4repair_space>" ) ; query . append ( InfluxDBPersistenceService . TIME_COLUMN_NAME ) ; query . append ( "<seq2seq4repair_space>" ) ; query . append ( "from<seq2seq4repair_space>" ) ; if ( ( filter . getItemName ( ) ) != null ) { query . append ( filter . getItemName ( ) ) ; } else { query . append ( "//.*//" ) ; } InfluxDBPersistenceService . logger . trace ( "filter<seq2seq4repair_space>itemname:<seq2seq4repair_space>{}" , filter . getItemName ( ) ) ; InfluxDBPersistenceService . logger . trace ( "filter<seq2seq4repair_space>ordering:<seq2seq4repair_space>{}" , filter . getOrdering ( ) . toString ( ) ) ; InfluxDBPersistenceService . logger . trace ( "filter<seq2seq4repair_space>state:<seq2seq4repair_space>{}" , filter . getState ( ) ) ; InfluxDBPersistenceService . logger . trace ( "filter<seq2seq4repair_space>operator:<seq2seq4repair_space>{}" , filter . getOperator ( ) ) ; InfluxDBPersistenceService . logger . trace ( "filter<seq2seq4repair_space>getBeginDate:<seq2seq4repair_space>{}" , filter . getBeginDate ( ) ) ; InfluxDBPersistenceService . logger . trace ( "filter<seq2seq4repair_space>getEndDate:<seq2seq4repair_space>{}" , filter . getEndDate ( ) ) ; InfluxDBPersistenceService . logger . trace ( "filter<seq2seq4repair_space>getPageSize:<seq2seq4repair_space>{}" , filter . getPageSize ( ) ) ; InfluxDBPersistenceService . logger . trace ( "filter<seq2seq4repair_space>getPageNumber:<seq2seq4repair_space>{}" , filter . getPageNumber ( ) ) ; if ( ( ( ( ( filter . getState ( ) ) != null ) && ( ( filter . getOperator ( ) ) != null ) ) || ( ( filter . getBeginDate ( ) ) != null ) ) || ( ( filter . getEndDate ( ) ) != null ) ) { query . append ( "<seq2seq4repair_space>where<seq2seq4repair_space>" ) ; boolean foundState = false ; boolean foundBeginDate = false ; if ( ( ( filter . getState ( ) ) != null ) && ( ( filter . getOperator ( ) ) != null ) ) { String value = stateToString ( filter . getState ( ) ) ; if ( value != null ) { foundState = true ; query . append ( InfluxDBPersistenceService . VALUE_COLUMN_NAME ) ; query . append ( "<seq2seq4repair_space>" ) ; query . append ( filter . getOperator ( ) . toString ( ) ) ; query . append ( "<seq2seq4repair_space>" ) ; query . append ( value ) ; } } if ( ( filter . getBeginDate ( ) ) != null ) { foundBeginDate = true ; if ( foundState ) { query . append ( "<seq2seq4repair_space>and" ) ; } query . append ( "<seq2seq4repair_space>" ) ; query . append ( InfluxDBPersistenceService . TIME_COLUMN_NAME ) ; query . append ( "<seq2seq4repair_space>><seq2seq4repair_space>" ) ; query . append ( getTimeFilter ( filter . getBeginDate ( ) ) ) ; query . append ( "<seq2seq4repair_space>" ) ; } if ( ( filter . getEndDate ( ) ) != null ) { if ( foundState || foundBeginDate ) { query . append ( "<seq2seq4repair_space>and" ) ; } query . append ( "<seq2seq4repair_space>" ) ; query . append ( InfluxDBPersistenceService . TIME_COLUMN_NAME ) ; query . append ( "<seq2seq4repair_space><<seq2seq4repair_space>" ) ; query . append ( getTimeFilter ( filter . getEndDate ( ) ) ) ; query . append ( "<seq2seq4repair_space>" ) ; } } if ( ( filter . getOrdering ( ) ) == ( Ordering . ASCENDING ) ) { query . append ( "<seq2seq4repair_space>order<seq2seq4repair_space>asc" ) ; } int limit = ( ( filter . getPageNumber ( ) ) + 1 ) * ( filter . getPageSize ( ) ) ; query . append ( ( "<seq2seq4repair_space>limit<seq2seq4repair_space>" + limit ) ) ; InfluxDBPersistenceService . logger . trace ( "appending<seq2seq4repair_space>limit<seq2seq4repair_space>{}" , limit ) ; int totalEntriesAffected = ( ( filter . getPageNumber ( ) ) + 1 ) * ( filter . getPageSize ( ) ) ; <START_BUG> int startEntryNum = totalEntriesAffected - ( totalEntriesAffected - ( filter . getPageSize ( ) ) ) ; <END_BUG> InfluxDBPersistenceService . logger . trace ( "startEntryNum<seq2seq4repair_space>{}" , startEntryNum ) ; InfluxDBPersistenceService . logger . debug ( "query<seq2seq4repair_space>string:<seq2seq4repair_space>{}" , query . toString ( ) ) ; List < Serie > results = Collections . emptyList ( ) ; try { results = influxDB . query ( dbName , query . toString ( ) , TimeUnit . MILLISECONDS ) ; } catch ( RuntimeException e ) { InfluxDBPersistenceService . logger . error ( "query<seq2seq4repair_space>failed<seq2seq4repair_space>with<seq2seq4repair_space>database<seq2seq4repair_space>error" ) ; handleDatabaseException ( e ) ; } for ( Serie result : results ) { String historicItemName = result . getName ( ) ; InfluxDBPersistenceService . logger . trace ( "item<seq2seq4repair_space>name<seq2seq4repair_space>{}" , historicItemName ) ; int entryCount = 0 ; for ( Map < String , Object > row : result . getRows ( ) ) { entryCount ++ ; if ( entryCount >= startEntryNum ) { Double rawTime = ( ( Double ) ( row . get ( InfluxDBPersistenceService . TIME_COLUMN_NAME ) ) ) ; Object rawValue = row . get ( InfluxDBPersistenceService . VALUE_COLUMN_NAME ) ; InfluxDBPersistenceService . logger . trace ( "adding<seq2seq4repair_space>historic<seq2seq4repair_space>item<seq2seq4repair_space>{}:<seq2seq4repair_space>time<seq2seq4repair_space>{}<seq2seq4repair_space>value<seq2seq4repair_space>{}" , historicItemName , rawTime , rawValue ) ; Date time = new Date ( rawTime . longValue ( ) ) ; State value = objectToState ( rawValue , historicItemName ) ; historicItems . add ( new InfluxdbItem ( historicItemName , value , time ) ) ; } else { InfluxDBPersistenceService . logger . trace ( "omitting<seq2seq4repair_space>item<seq2seq4repair_space>value<seq2seq4repair_space>for<seq2seq4repair_space>{}" , historicItemName ) ; } } } return historicItems ; } private String getTimeFilter ( Date time ) { } private Object convertBigDecimalToNum ( BigDecimal value ) { } private Object stateToObject ( State state ) { } private String stateToString ( State state ) { } private State objectToState ( Object value , String itemName ) { } }

Fix:
int startEntryNum = totalEntriesAffected - ( totalEntriesAffected - ( ( filter . getPageSize ( ) ) * ( filter . getPageNumber ( ) ) ) ) ;