From cab6d7565efe4f46ddf50a7c601c0910fe918f7b Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Tue, 23 May 2023 10:15:22 +0300 Subject: [PATCH] Limit subclass codec registration to known working codecs Fixes: #33458 (cherry picked from commit 827dfa0e48ee6044670d67caed312f6d171c882f) --- .../vertx/deployment/EventBusCodecProcessor.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/extensions/vertx/deployment/src/main/java/io/quarkus/vertx/deployment/EventBusCodecProcessor.java b/extensions/vertx/deployment/src/main/java/io/quarkus/vertx/deployment/EventBusCodecProcessor.java index f64a54cdab508..8dd0ee0830df5 100644 --- a/extensions/vertx/deployment/src/main/java/io/quarkus/vertx/deployment/EventBusCodecProcessor.java +++ b/extensions/vertx/deployment/src/main/java/io/quarkus/vertx/deployment/EventBusCodecProcessor.java @@ -29,6 +29,7 @@ import io.quarkus.deployment.annotations.BuildStep; import io.quarkus.deployment.builditem.CombinedIndexBuildItem; import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem; +import io.quarkus.vertx.LocalEventBusCodec; import io.vertx.core.buffer.Buffer; import io.vertx.core.json.JsonArray; import io.vertx.core.json.JsonObject; @@ -38,6 +39,7 @@ public class EventBusCodecProcessor { private static final Logger LOGGER = Logger.getLogger(EventBusCodecProcessor.class.getName()); private static final DotName OBJECT = DotName.createSimple(Object.class); + private static final DotName LOCAL_EVENT_BUT_CODEC = DotName.createSimple(LocalEventBusCodec.class); @BuildStep public void registerCodecs( @@ -101,17 +103,25 @@ public void registerCodecs( // But do not override the existing ones for (Map.Entry entry : codecByTypes.entrySet()) { // we do not consider Object as it would be a mess - if (OBJECT.equals(entry.getKey())) { + DotName typeDotName = entry.getKey(); + if (OBJECT.equals(typeDotName)) { continue; } - Set subclasses = combinedIndex.getIndex().getAllKnownSubclasses(entry.getKey()).stream() + DotName codecDotName = entry.getValue(); + // we have to limit subclasses to codecs we know that have unique name per-instance + // see: https://github.com/quarkusio/quarkus/issues/33458 + if (!LOCAL_EVENT_BUT_CODEC.equals(codecDotName)) { + continue; + } + + Set subclasses = combinedIndex.getIndex().getAllKnownSubclasses(typeDotName).stream() .map(ci -> ci.name()) .filter(d -> !codecByTypes.containsKey(d)) .collect(Collectors.toSet()); for (DotName subclass : subclasses) { - messageCodecs.produce(new MessageCodecBuildItem(subclass.toString(), entry.getValue().toString())); + messageCodecs.produce(new MessageCodecBuildItem(subclass.toString(), codecDotName.toString())); } }