diff --git a/.github/workflows/_meta-build.yaml b/.github/workflows/_meta-build.yaml index 6c2651b6ce..534556becd 100644 --- a/.github/workflows/_meta-build.yaml +++ b/.github/workflows/_meta-build.yaml @@ -34,7 +34,7 @@ jobs: uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # tag=v4.2.1 with: distribution: 'temurin' - java-version: '17' + java-version: '21' cache: 'maven' - name: Setup CycloneDX CLI diff --git a/.github/workflows/ci-release.yaml b/.github/workflows/ci-release.yaml index fb12df5410..d340410adf 100644 --- a/.github/workflows/ci-release.yaml +++ b/.github/workflows/ci-release.yaml @@ -57,7 +57,7 @@ jobs: uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # tag=v4.2.1 with: distribution: 'temurin' - java-version: '17' + java-version: '21' cache: 'maven' - name: Set Version diff --git a/.github/workflows/ci-test.yaml b/.github/workflows/ci-test.yaml index 8b1793ef63..b5a4281479 100644 --- a/.github/workflows/ci-test.yaml +++ b/.github/workflows/ci-test.yaml @@ -39,7 +39,7 @@ jobs: uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # tag=v4.2.1 with: distribution: 'temurin' - java-version: '17' + java-version: '21' cache: 'maven' - name: Execute unit tests diff --git a/DEVELOPING.md b/DEVELOPING.md index 03bfb0460a..63584c7d40 100644 --- a/DEVELOPING.md +++ b/DEVELOPING.md @@ -18,7 +18,7 @@ This document primarily covers the API server. Please refer to the frontend repo There are a few things you'll need on your journey: -* JDK 17+ ([Temurin](https://adoptium.net/temurin/releases) distribution recommended) +* JDK 21+ ([Temurin](https://adoptium.net/temurin/releases) distribution recommended) * Maven (comes bundled with IntelliJ and Eclipse) * A Java IDE of your preference (we recommend IntelliJ, but any other IDE is fine as well) * Docker (optional) diff --git a/pom.xml b/pom.xml index 05f08fddd5..3707d434ee 100644 --- a/pom.xml +++ b/pom.xml @@ -80,6 +80,10 @@ + + 21 + 21 + 4.11.0 ${project.parent.version} diff --git a/src/main/java/org/dependencytrack/tasks/NistApiMirrorTask.java b/src/main/java/org/dependencytrack/tasks/NistApiMirrorTask.java index d82ac2ae8e..ebea83b0c3 100644 --- a/src/main/java/org/dependencytrack/tasks/NistApiMirrorTask.java +++ b/src/main/java/org/dependencytrack/tasks/NistApiMirrorTask.java @@ -146,13 +146,12 @@ public void inform(final Event e) { .namingPattern(getClass().getSimpleName() + "-%d") .uncaughtExceptionHandler(new LoggableUncaughtExceptionHandler()) .build(); - final var executor = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.SECONDS, new LinkedBlockingQueue<>(), factory); final long startTimeNs = System.nanoTime(); final var numMirrored = new AtomicInteger(0); ZonedDateTime lastModified; try (final NvdCveClient client = createApiClient(apiUrl, apiKey, lastModifiedEpochSeconds)) { - try { + try (final var executor = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.SECONDS, new LinkedBlockingQueue<>(), factory)) { while (client.hasNext()) { for (final DefCveItem defCveItem : client.next()) { final CveItem cveItem = defCveItem.getCve(); @@ -186,28 +185,6 @@ public void inform(final Event e) { }); } } - } finally { - // Copied from ExecutorService#close (available since JDK 19). - // This code can be replaced with try-with-resources after upgrade to Java 21. - // https://github.com/openjdk/jdk/blob/890adb6410dab4606a4f26a942aed02fb2f55387/src/java.base/share/classes/java/util/concurrent/ExecutorService.java#L410-L429 - boolean terminated = executor.isTerminated(); - if (!terminated) { - executor.shutdown(); - boolean interrupted = false; - while (!terminated) { - try { - terminated = executor.awaitTermination(1L, TimeUnit.DAYS); - } catch (InterruptedException ex) { - if (!interrupted) { - executor.shutdownNow(); - interrupted = true; - } - } - } - if (interrupted) { - Thread.currentThread().interrupt(); - } - } } lastModified = client.getLastUpdated();