From 713ccf831d381aaa94734d9ddc835636cf52f21e Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Wed, 15 Jan 2025 12:58:56 +0200 Subject: [PATCH] Remove the use of UUID in startup code Follow up of: #45434 --- .../io/quarkus/vertx/http/runtime/QuarkusErrorHandler.java | 7 +++++-- .../io/quarkus/vertx/core/runtime/VertxCoreRecorder.java | 5 ++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/QuarkusErrorHandler.java b/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/QuarkusErrorHandler.java index afbde7e136bff..76ff73fd935d8 100644 --- a/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/QuarkusErrorHandler.java +++ b/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/QuarkusErrorHandler.java @@ -46,7 +46,6 @@ public class QuarkusErrorHandler implements Handler { * we don't want to generate a new UUID each time as it is slowish. Instead, we just generate one based one * and then use a counter. */ - private static final String BASE_ID = UUID.randomUUID() + "-"; private static final AtomicLong ERROR_COUNT = new AtomicLong(); @@ -148,7 +147,7 @@ public void accept(Throwable throwable) { event.response().setStatusCode(event.statusCode() > 0 ? event.statusCode() : 500); } - String uuid = BASE_ID + ERROR_COUNT.incrementAndGet(); + String uuid = LazyHolder.BASE_ID + ERROR_COUNT.incrementAndGet(); String details; String stack = ""; Throwable exception = event.failure(); @@ -427,4 +426,8 @@ static String pickFirstSupportedAndAcceptedContentType(RoutingContext context) { } } } + + private static class LazyHolder { + private static final String BASE_ID = UUID.randomUUID() + "-"; + } } diff --git a/extensions/vertx/runtime/src/main/java/io/quarkus/vertx/core/runtime/VertxCoreRecorder.java b/extensions/vertx/runtime/src/main/java/io/quarkus/vertx/core/runtime/VertxCoreRecorder.java index 15ab4cd34fc98..c28172f0e7567 100644 --- a/extensions/vertx/runtime/src/main/java/io/quarkus/vertx/core/runtime/VertxCoreRecorder.java +++ b/extensions/vertx/runtime/src/main/java/io/quarkus/vertx/core/runtime/VertxCoreRecorder.java @@ -15,8 +15,8 @@ import java.util.Locale; import java.util.Map; import java.util.Optional; +import java.util.Random; import java.util.Set; -import java.util.UUID; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.CountDownLatch; @@ -395,8 +395,7 @@ public void run() { } private static File getRandomDirectory(File tmp) { - long random = Math.abs(UUID.randomUUID().getMostSignificantBits()); - File cache = new File(tmp, Long.toString(random)); + File cache = new File(tmp, Long.toString(new Random().nextLong())); if (cache.isDirectory()) { // Do not reuse an existing directory. return getRandomDirectory(tmp);