From b8094eb7d507d4f24ab77f0131671f6da2cf70c4 Mon Sep 17 00:00:00 2001 From: Foivos Zakkak Date: Fri, 17 May 2024 15:32:01 +0300 Subject: [PATCH] Substitute `getUnsafe` of shaded `protobuf.UnsafeUtil` in kafka Duplicate of the substitution in `GrpcSubstitutions` of the unshaded class. Fixes: https://github.com/quarkusio/quarkus/issues/40100 --- .../kafka/graal/KafkaSubstitutions.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/extensions/kafka-client/runtime/src/main/java/io/smallrye/reactive/kafka/graal/KafkaSubstitutions.java b/extensions/kafka-client/runtime/src/main/java/io/smallrye/reactive/kafka/graal/KafkaSubstitutions.java index 852c6ca247a6e1..8325fdd9c472f4 100644 --- a/extensions/kafka-client/runtime/src/main/java/io/smallrye/reactive/kafka/graal/KafkaSubstitutions.java +++ b/extensions/kafka-client/runtime/src/main/java/io/smallrye/reactive/kafka/graal/KafkaSubstitutions.java @@ -1,10 +1,13 @@ package io.smallrye.reactive.kafka.graal; +import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import com.oracle.svm.core.annotate.Substitute; import com.oracle.svm.core.annotate.TargetClass; +import sun.misc.Unsafe; + @TargetClass(className = "org.apache.kafka.common.network.SaslChannelBuilder") final class Target_org_apache_kafka_common_network_SaslChannelBuilder { @@ -17,6 +20,20 @@ private static String defaultKerberosRealm() throws ClassNotFoundException, NoSu } +@TargetClass(className = "org.apache.kafka.shaded.com.google.protobuf.UnsafeUtil") +final class Target_org_apache_kafka_shaded_com_google_protobuf_UnsafeUtil { + @Substitute + static sun.misc.Unsafe getUnsafe() { + try { + Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe"); + theUnsafe.setAccessible(true); + return (Unsafe) theUnsafe.get(null); + } catch (Exception e) { + throw new RuntimeException(e); + } + } +} + class KafkaSubstitutions { }