Skip to content

Commit

Permalink
Prevent build failure when @Blocking on Application
Browse files Browse the repository at this point in the history
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:
redhat-developer-demos/quarkus-petclinic#23
  • Loading branch information
geoand committed Jul 6, 2023
1 parent 8a06248 commit 0cfba8c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <tt>name</tt>.
*
* @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<DotName> additionalIgnoredSuperClasses) {
// Check interfaces
List<DotName> interfaceNames = info.interfaceNames();
for (DotName interfaceName : interfaceNames) {
Expand All @@ -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)) {
Expand All @@ -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);
}

}

0 comments on commit 0cfba8c

Please sign in to comment.