Buggy code:
@ Service @ DependsOn ( "persistenceSQLAccess" ) public class DataCollectionService { @ Autowired private JsonConverter jsonConverter ; @ Autowired private XmlConverter xmlConverter ; static final Logger log = LoggerFactory . getLogger ( DataCollectionService . class ) ; static final Logger performanceLog = LoggerFactory . getLogger ( "PerformanceLogger" ) ; private Map < String , AbstractDataAccess > dataAccesses ; private Map < String , Requirements > requirementsConfiguration ; private Map < String , CompositionRulesConfiguration > compositionRulesConfigurations ; private Map < String , MonitoredElement > serviceConfigurations ; private Map < String , List < ServiceMonitoringSnapshot > > historicalMonitoringDatas ; @ Value ( "${monitoring.polling.interval:1}" ) private int monitoringIntervalInSeconds ; @ Value ( "${monitoring.aggregation.windowsize:2}" ) private int aggregationWindowsCount ; @ Value ( "${dataservice.behavior.monitoring}" ) private boolean monitoring ; private Map < String , Timer > monitoringTimers ; private Map < String , List < Action > > actionsInExecution ; Timer monitoringMemUsageTimer ; @ Autowired private DataAggregationEngine instantMonitoringDataEnrichmentEngine ; @ Autowired private PersistenceDelegate persistenceSQLAccess ; @ Autowired private ApplicationContext context ; private ExecutorService scheduler ; @ PostConstruct public void init ( ) { } public synchronized Collection < MonitoredElement > getServiceConfiguration ( ) { } public synchronized void addExecutingActions ( String serviceID , List < Action > actions ) { } public synchronized void removeExecutingActions ( String serviceID , List < Action > actions ) { } public synchronized void addConfiguration ( ConfigurationXMLRepresentation configurationXMLRepresentation ) { } public synchronized void addService ( MonitoredElement serviceConfiguration ) { } public synchronized void removeService ( String serviceID ) { } public synchronized void addRequirements ( String serviceID , Requirements requirements ) { } public synchronized void updateServiceConfiguration ( MonitoredElement serviceConfiguration ) { } public synchronized void setCompositionRulesConfiguration ( String serviceID , CompositionRulesConfiguration compositionRulesConfiguration ) { } public synchronized ServiceMonitoringSnapshot getRawMonitoringData ( String serviceID ) { } public ServiceMonitoringSnapshot getAggregatedMonitoringDataOverTime ( String serviceID , List < ServiceMonitoringSnapshot > serviceMonitoringSnapshots ) { } public Collection < Metric > getAvailableMetricsForMonitoredElement ( String serviceID , MonitoredElement MonitoredElement ) { } public synchronized void addMetricFilter ( String serviceID , MetricFilter metricFilter ) { } public synchronized void addMetricFilters ( String serviceID , Collection < MetricFilter > newFilters ) { } public synchronized void removeMetricFilter ( String serviceID , MetricFilter metricFilter ) { } public synchronized void removeMetricFilters ( String serviceID , Collection < MetricFilter > filtersToRemove ) { } public synchronized void setMonitoringIntervalInSeconds ( int monitoringIntervalInSeconds ) { } public synchronized void setNrOfMonitoringWindowsToAggregate ( int aggregationIntervalInSeconds ) { } public synchronized void startMonitoring ( final String serviceID ) { } public synchronized void stopMonitoring ( ) { } public String getLatestMonitoringDataINJSON ( String serviceID ) { } public MonitoredElement getLatestServiceStructure ( String serviceID ) { } public MonitoredElementMonitoringSnapshot getLatestMonitoringDataInXML ( String serviceID ) { } public MonitoredElementMonitoringSnapshot getLatestMonitoringData ( String serviceID , MonitoredElement element ) { } public MonitoredElementMonitoringSnapshots getAllAggregatedMonitoringData ( String serviceID ) { List < ServiceMonitoringSnapshot > dataFromTimestamp = new ArrayList < > ( ) ; ServiceMonitoringSnapshot latestMonitoringSnapshot = persistenceSQLAccess . extractLatestMonitoringData ( serviceID ) ; Integer lastTimestampID = ( latestMonitoringSnapshot == null ) ? Integer . MAX_VALUE : latestMonitoringSnapshot . getTimestampID ( ) ; int currentImestamp = 0 ; do { <START_BUG> dataFromTimestamp = persistenceSQLAccess . extractMonitoringDataByTimeInterval ( currentImestamp , ( currentImestamp + 1000 ) , serviceID ) ; <END_BUG> currentImestamp += 1000 ; if ( dataFromTimestamp != null ) { Iterator < ServiceMonitoringSnapshot > it = dataFromTimestamp . iterator ( ) ; while ( it . hasNext ( ) ) { Integer timestampID = it . next ( ) . getTimestampID ( ) ; if ( timestampID > lastTimestampID ) { it . remove ( ) ; } } } } while ( ( ( dataFromTimestamp != null ) && ( ! ( dataFromTimestamp . isEmpty ( ) ) ) ) && ( currentImestamp < lastTimestampID ) ) ; List < MonitoredElementMonitoringSnapshot > elementMonitoringSnapshots = new ArrayList < MonitoredElementMonitoringSnapshot > ( ) ; for ( ServiceMonitoringSnapshot monitoringSnapshot : dataFromTimestamp ) { elementMonitoringSnapshots . add ( monitoringSnapshot . getMonitoredData ( SERVICE ) . values ( ) . iterator ( ) . next ( ) ) ; } MonitoredElementMonitoringSnapshots snapshots = new MonitoredElementMonitoringSnapshots ( ) ; snapshots . setChildren ( elementMonitoringSnapshots ) ; return snapshots ; } public MonitoredElementMonitoringSnapshots getAllAggregatedMonitoringDataFromTimestamp ( String serviceID , long timestamp ) { } public MonitoredElementMonitoringSnapshots getAggregatedMonitoringDataInTimeInterval ( String serviceID , long startTimestampID , long endTimestampID ) { } public MonitoredElementMonitoringSnapshots getLastXAggregatedMonitoringData ( String serviceID , int count ) { } public String getMetricCompositionRules ( String serviceID ) { } public CompositionRulesConfiguration getMetricCompositionRulesXML ( String serviceID ) { } public boolean testIfServiceIsHealthy ( String serviceID ) { } public String getAllManagedServicesIDs ( ) { } public String getEvents ( String serviceID ) { } public void writeEvents ( String serviceID , String event ) { } }

Fix:
dataFromTimestamp = persistenceSQLAccess . extractMonitoringDataByTimestampIDsInterval ( currentImestamp , ( currentImestamp + 1000 ) , serviceID ) ;