From 0cfba8c245641b9949f3c8692f7a623005494deb Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Thu, 6 Jul 2023 10:55:57 +0300 Subject: [PATCH] Prevent build failure when @Blocking on Application This would happen when @Blocking was used on a class that extended Jakarta REST's Application class and the Reactive REST Client extension was present The issue was originally reported at: https://github.com/redhat-developer-demos/quarkus-petclinic/pull/23 --- .../RestClientReactiveProcessor.java | 3 ++- .../reactive/common/processor/JandexUtil.java | 22 ++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/extensions/resteasy-reactive/rest-client-reactive/deployment/src/main/java/io/quarkus/rest/client/reactive/deployment/RestClientReactiveProcessor.java b/extensions/resteasy-reactive/rest-client-reactive/deployment/src/main/java/io/quarkus/rest/client/reactive/deployment/RestClientReactiveProcessor.java index cd72108fecec6..b4fba326dc0fc 100644 --- a/extensions/resteasy-reactive/rest-client-reactive/deployment/src/main/java/io/quarkus/rest/client/reactive/deployment/RestClientReactiveProcessor.java +++ b/extensions/resteasy-reactive/rest-client-reactive/deployment/src/main/java/io/quarkus/rest/client/reactive/deployment/RestClientReactiveProcessor.java @@ -15,6 +15,7 @@ import static java.util.stream.Collectors.*; import static org.jboss.resteasy.reactive.common.processor.EndpointIndexer.CDI_WRAPPER_SUFFIX; import static org.jboss.resteasy.reactive.common.processor.JandexUtil.isImplementorOf; +import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.APPLICATION; import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.BLOCKING; import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.REQUEST_SCOPED; import static org.jboss.resteasy.reactive.common.processor.scanning.ResteasyReactiveScanner.BUILTIN_HTTP_ANNOTATIONS_TO_METHOD; @@ -523,7 +524,7 @@ void addRestClientBeans(Capabilities capabilities, for (AnnotationInstance registerBlockingClass : registerBlockingClasses) { AnnotationTarget target = registerBlockingClass.target(); if (target.kind() == AnnotationTarget.Kind.CLASS - && isImplementorOf(index, target.asClass(), RESPONSE_EXCEPTION_MAPPER)) { + && isImplementorOf(index, target.asClass(), RESPONSE_EXCEPTION_MAPPER, Set.of(APPLICATION))) { // Watch for @Blocking annotations in classes that implements ResponseExceptionMapper: blockingClassNames.add(target.asClass().toString()); } else if (target.kind() == AnnotationTarget.Kind.METHOD diff --git a/independent-projects/resteasy-reactive/common/processor/src/main/java/org/jboss/resteasy/reactive/common/processor/JandexUtil.java b/independent-projects/resteasy-reactive/common/processor/src/main/java/org/jboss/resteasy/reactive/common/processor/JandexUtil.java index 092264d4c8263..8eb2a5d725bf9 100644 --- a/independent-projects/resteasy-reactive/common/processor/src/main/java/org/jboss/resteasy/reactive/common/processor/JandexUtil.java +++ b/independent-projects/resteasy-reactive/common/processor/src/main/java/org/jboss/resteasy/reactive/common/processor/JandexUtil.java @@ -373,6 +373,20 @@ public static boolean isSubclassOf(IndexView index, ClassInfo info, DotName pare * @throws RuntimeException if one of the superclasses is not indexed. */ public static boolean isImplementorOf(IndexView index, ClassInfo info, DotName name) { + return isImplementorOf(index, info, name, Collections.emptySet()); + } + + /** + * Returns true if the given Jandex ClassInfo is a subclass of or inherits the given name. + * + * @param index the index to use to look up super classes. + * @param info the ClassInfo we want to check. + * @param name the name of the superclass or interface we want to find. + * @param additionalIgnoredSuperClasses return false if the class has any of these as a superclass. + * @throws RuntimeException if one of the superclasses is not indexed. + */ + public static boolean isImplementorOf(IndexView index, ClassInfo info, DotName name, + Set additionalIgnoredSuperClasses) { // Check interfaces List interfaceNames = info.interfaceNames(); for (DotName interfaceName : interfaceNames) { @@ -382,7 +396,9 @@ public static boolean isImplementorOf(IndexView index, ClassInfo info, DotName n } // Check direct hierarchy - if (info.superName().equals(DOTNAME_OBJECT) || info.superName().equals(DOTNAME_RECORD)) { + DotName superDotName = info.superName(); + if (superDotName.equals(DOTNAME_OBJECT) || superDotName.equals(DOTNAME_RECORD) + || additionalIgnoredSuperClasses.contains(superDotName)) { return false; } if (info.superName().equals(name)) { @@ -393,10 +409,10 @@ public static boolean isImplementorOf(IndexView index, ClassInfo info, DotName n Type superType = info.superClassType(); ClassInfo superClass = index.getClassByName(superType.name()); if (superClass == null) { - // this can happens if the parent is not inside the Jandex index + // this can happen if the parent is not inside the Jandex index throw new RuntimeException("The class " + superType.name() + " is not inside the Jandex index"); } - return isImplementorOf(index, superClass, name); + return isImplementorOf(index, superClass, name, additionalIgnoredSuperClasses); } }