From f727e3ef1058904be32908b31fa3c7155565ac74 Mon Sep 17 00:00:00 2001 From: Paul Ferraro Date: Tue, 21 May 2024 17:58:16 -0400 Subject: [PATCH] WFLY-19355 AnnotationScanner implementations are not stateless and cannot be shared between deployments. --- .../OpenAPIModelServiceConfigurator.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/microprofile/openapi-smallrye/src/main/java/org/wildfly/extension/microprofile/openapi/deployment/OpenAPIModelServiceConfigurator.java b/microprofile/openapi-smallrye/src/main/java/org/wildfly/extension/microprofile/openapi/deployment/OpenAPIModelServiceConfigurator.java index 4a2c514b8558..cffa9cc14589 100644 --- a/microprofile/openapi-smallrye/src/main/java/org/wildfly/extension/microprofile/openapi/deployment/OpenAPIModelServiceConfigurator.java +++ b/microprofile/openapi-smallrye/src/main/java/org/wildfly/extension/microprofile/openapi/deployment/OpenAPIModelServiceConfigurator.java @@ -82,12 +82,6 @@ public class OpenAPIModelServiceConfigurator extends SimpleServiceNameProvider i private static final String RELATIVE_SERVER_URLS = "mp.openapi.extensions.servers.relative"; private static final String DEFAULT_TITLE = "Generated API"; private static final Set REQUISITE_LISTENERS = Collections.singleton("http"); - private static final Iterable SCANNERS = WildFlySecurityManager.doUnchecked(new PrivilegedAction<>() { - @Override - public Iterable run() { - return ServiceLoader.load(AnnotationScanner.class, AnnotationScanner.class.getClassLoader()).stream().map(ServiceLoader.Provider::get).collect(Collectors.toList()); - } - }); static { // Set the static OASFactoryResolver eagerly avoiding the need perform TCCL service loading later @@ -159,7 +153,14 @@ public OpenAPI get() { } } - document.modelFromAnnotations(OpenApiProcessor.modelFromAnnotations(config, this.module.getClassLoader(), indexView, Functions.constantSupplier(SCANNERS))); + // AnnotationScanner implementations are not stateless, so we must create new instances per deployment + Iterable scanners = WildFlySecurityManager.doUnchecked(new PrivilegedAction<>() { + @Override + public Iterable run() { + return ServiceLoader.load(AnnotationScanner.class, AnnotationScanner.class.getClassLoader()).stream().map(ServiceLoader.Provider::get).collect(Collectors.toList()); + } + }); + document.modelFromAnnotations(OpenApiProcessor.modelFromAnnotations(config, this.module.getClassLoader(), indexView, Functions.constantSupplier(scanners))); document.filter(OpenApiProcessor.getFilter(config, this.module.getClassLoader(), indexView)); document.initialize(); OpenAPI model = document.get();