Skip to content

Commit

Permalink
Limit subclass codec registration to known working codecs
Browse files Browse the repository at this point in the history
Fixes: #33458
(cherry picked from commit 827dfa0)
  • Loading branch information
geoand authored and gsmet committed May 23, 2023
1 parent 5ebbf9c commit cab6d75
Showing 1 changed file with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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(
Expand Down Expand Up @@ -101,17 +103,25 @@ public void registerCodecs(
// But do not override the existing ones
for (Map.Entry<DotName, DotName> 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<DotName> 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<DotName> 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()));
}
}

Expand Down

0 comments on commit cab6d75

Please sign in to comment.