From 5f8c7f1f3755d98aa4e4d1321c8c3b3a03c8931d Mon Sep 17 00:00:00 2001 From: franz1981 Date: Wed, 21 Jun 2023 10:49:21 +0200 Subject: [PATCH] findResourceWriters often creates HashSets and ArrayLists while not necessary --- .../jboss/resteasy/reactive/common/core/Serialisers.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/core/Serialisers.java b/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/core/Serialisers.java index 18cbc955d960fe..2280983015cdb9 100644 --- a/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/core/Serialisers.java +++ b/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/core/Serialisers.java @@ -164,7 +164,7 @@ protected List findResourceWriters(QuarkusMultivaluedMap ret = new ArrayList<>(); Deque> toProcess = new LinkedList<>(); do { - if (currentClass == Object.class) { + if (currentClass == Object.class && !toProcess.isEmpty()) { //spec extension, look for interfaces as well //we match interfaces before Object Set> seen = new HashSet<>(toProcess); @@ -182,13 +182,16 @@ protected List findResourceWriters(QuarkusMultivaluedMap goodTypeWriters = writers.get(currentClass); writerLookup(runtimeType, produces, desired, ret, goodTypeWriters); - toProcess.addAll(Arrays.asList(currentClass.getInterfaces())); + var prevClass = currentClass; // if we're an interface, pretend our superclass is Object to get us through the same logic as a class if (currentClass.isInterface()) { currentClass = Object.class; } else { currentClass = currentClass.getSuperclass(); } + if (currentClass != null) { + toProcess.addAll(List.of(prevClass.getInterfaces())); + } } while (currentClass != null); return ret;