From 44c2fe7418880726eccc3cb0bf7ac9e06b3174f1 Mon Sep 17 00:00:00 2001 From: LSmyrnaios Date: Fri, 20 Oct 2023 14:25:05 +0300 Subject: [PATCH] - Fix the "IndexOutOfBoundsException", when checking the futures' results. - Update dependencies. --- build.gradle | 8 ++++---- .../urls_controller/components/ScheduledTasks.java | 9 ++++++++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/build.gradle b/build.gradle index ea54276..b6b611a 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'org.springframework.boot' version '2.7.16' + id 'org.springframework.boot' version '2.7.17' id 'io.spring.dependency-management' version '1.1.3' id 'java' } @@ -43,7 +43,7 @@ dependencies { //implementation group: 'jakarta.validation', name: 'jakarta.validation-api', version: '3.0.2' // https://mvnrepository.com/artifact/com.google.guava/guava - implementation group: 'com.google.guava', name: 'guava', version: '32.1.2-jre' + implementation group: 'com.google.guava', name: 'guava', version: '32.1.3-jre' // https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.13.0' @@ -113,14 +113,14 @@ dependencies { implementation 'com.fasterxml.woodstox:woodstox-core:6.5.1' // https://mvnrepository.com/artifact/org.json/json - implementation 'org.json:json:20230618' + implementation 'org.json:json:20231013' // https://mvnrepository.com/artifact/com.google.code.gson/gson implementation 'com.google.code.gson:gson:2.10.1' // https://mvnrepository.com/artifact/io.micrometer/micrometer-registry-prometheus - runtimeOnly 'io.micrometer:micrometer-registry-prometheus:1.11.4' + runtimeOnly 'io.micrometer:micrometer-registry-prometheus:1.11.5' testImplementation 'org.springframework.security:spring-security-test' testImplementation "org.springframework.boot:spring-boot-starter-test" diff --git a/src/main/java/eu/openaire/urls_controller/components/ScheduledTasks.java b/src/main/java/eu/openaire/urls_controller/components/ScheduledTasks.java index 489fb0e..866d134 100644 --- a/src/main/java/eu/openaire/urls_controller/components/ScheduledTasks.java +++ b/src/main/java/eu/openaire/urls_controller/components/ScheduledTasks.java @@ -24,7 +24,9 @@ import org.springframework.stereotype.Component; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; +import java.util.ArrayList; import java.util.Date; +import java.util.List; import java.util.Set; import java.util.concurrent.CancellationException; import java.util.concurrent.ExecutionException; @@ -100,6 +102,8 @@ public class ScheduledTasks { int numFailedTasks = 0; + List> futuresToDelete = new ArrayList<>(sizeOfFutures); + for ( int i=0; i < sizeOfFutures; ++i ) { Future future = null; try { @@ -121,10 +125,13 @@ public class ScheduledTasks { // Only here, the "future" will be null. } finally { if ( future != null ) - UrlsController.futuresOfBackgroundTasks.remove(future); // We do not need it anymore. This is the safest way to delete them without removing newly added futures as well. + futuresToDelete.add(future); // Do not delete them directly here, as the indexes will get messed up and we will get "IOOBE". } } + for ( Future future : futuresToDelete ) + UrlsController.futuresOfBackgroundTasks.remove(future); // We do not need it anymore. This is the safest way to delete them without removing newly added futures as well. + if ( numFailedTasks > 0 ) logger.warn(numFailedTasks + " out of " + sizeOfFutures + " tasks have failed!"); else