diff --git a/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/StaticResourcesRecorder.java b/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/StaticResourcesRecorder.java index 5c9c0061e125e6..844fc9649ef62d 100644 --- a/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/StaticResourcesRecorder.java +++ b/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/StaticResourcesRecorder.java @@ -1,5 +1,7 @@ package io.quarkus.vertx.http.runtime; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.VarHandle; import java.nio.file.Path; import java.util.ArrayList; import java.util.List; @@ -20,12 +22,22 @@ public class StaticResourcesRecorder { private static volatile Set knownPaths; private static volatile List hotDeploymentResourcePaths; + private static final VarHandle KNOWN_PATHS_MH; + + static { + try { + KNOWN_PATHS_MH = MethodHandles.lookup().findStaticVarHandle(StaticResourcesRecorder.class, "knownPaths", Set.class); + } catch (NoSuchFieldException | IllegalAccessException e) { + throw new Error(e); + } + } + public static void setHotDeploymentResources(List resources) { hotDeploymentResourcePaths = resources; } public void staticInit(Set knownPaths) { - StaticResourcesRecorder.knownPaths = knownPaths; + KNOWN_PATHS_MH.setRelease(knownPaths); } public Consumer start() { @@ -40,13 +52,16 @@ public Consumer start() { staticHandler.setAllowRootFileSystemAccess(true); staticHandler.setWebRoot(root); staticHandler.setDefaultContentEncoding("UTF-8"); - handlers.add(event -> { - try { - staticHandler.handle(event); - } catch (Exception e) { - // on Windows, the drive in file path screws up cache lookup - // so just punt to next handler - event.next(); + handlers.add(new Handler<>() { + @Override + public void handle(RoutingContext event) { + try { + staticHandler.handle(event); + } catch (Exception e) { + // on Windows, the drive in file path screws up cache lookup + // so just punt to next handler + event.next(); + } } }); } @@ -54,22 +69,25 @@ public Consumer start() { if (!knownPaths.isEmpty()) { ClassLoader currentCl = Thread.currentThread().getContextClassLoader(); StaticHandler staticHandler = StaticHandler.create(META_INF_RESOURCES).setDefaultContentEncoding("UTF-8"); - handlers.add(ctx -> { - String rel = ctx.mountPoint() == null ? ctx.normalisedPath() - : ctx.normalisedPath().substring( - // let's be extra careful here in case Vert.x normalizes the mount points at some point - ctx.mountPoint().endsWith("/") ? ctx.mountPoint().length() - 1 : ctx.mountPoint().length()); - if (knownPaths.contains(rel)) { - staticHandler.handle(ctx); - } else { - // make sure we don't lose the correct TCCL to Vert.x... - Thread.currentThread().setContextClassLoader(currentCl); - ctx.next(); + handlers.add(new Handler<>() { + @Override + public void handle(RoutingContext ctx) { + String rel = ctx.mountPoint() == null ? ctx.normalizedPath() + : ctx.normalizedPath().substring( + // let's be extra careful here in case Vert.x normalizes the mount points at some point + ctx.mountPoint().endsWith("/") ? ctx.mountPoint().length() - 1 : ctx.mountPoint().length()); + if (((Set) KNOWN_PATHS_MH.getAcquire()).contains(rel)) { + staticHandler.handle(ctx); + } else { + // make sure we don't lose the correct TCCL to Vert.x... + Thread.currentThread().setContextClassLoader(currentCl); + ctx.next(); + } } }); } - return new Consumer() { + return new Consumer<>() { @Override public void accept(Route route) {