From 37f368125608270887eb2a5545d5399fdabd581a Mon Sep 17 00:00:00 2001 From: Guillaume Smet Date: Wed, 22 Feb 2023 17:43:44 +0100 Subject: [PATCH] Also set io.netty.noUnsafe at runtime when set at build time Fixes #31349 --- .../io/quarkus/netty/deployment/NettyProcessor.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/extensions/netty/deployment/src/main/java/io/quarkus/netty/deployment/NettyProcessor.java b/extensions/netty/deployment/src/main/java/io/quarkus/netty/deployment/NettyProcessor.java index de1471c3ae4df..261f4d29f141f 100644 --- a/extensions/netty/deployment/src/main/java/io/quarkus/netty/deployment/NettyProcessor.java +++ b/extensions/netty/deployment/src/main/java/io/quarkus/netty/deployment/NettyProcessor.java @@ -31,6 +31,7 @@ import io.quarkus.deployment.builditem.nativeimage.RuntimeReinitializedClassBuildItem; import io.quarkus.deployment.builditem.nativeimage.UnsafeAccessedFieldBuildItem; import io.quarkus.deployment.logging.LogCleanupFilterBuildItem; +import io.quarkus.deployment.pkg.steps.NativeOrNativeSourcesBuild; import io.quarkus.netty.BossEventLoopGroup; import io.quarkus.netty.MainEventLoopGroup; import io.quarkus.netty.runtime.EmptyByteBufStub; @@ -77,10 +78,11 @@ public SystemPropertyBuildItem setNettyMachineId() { return new SystemPropertyBuildItem("io.netty.machineId", nettyMachineId); } - @BuildStep + @BuildStep(onlyIf = NativeOrNativeSourcesBuild.class) NativeImageConfigBuildItem build( NettyBuildTimeConfig config, BuildProducer reflectiveClass, + BuildProducer systemProperties, List minMaxOrderBuildItems) { reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, "io.netty.channel.socket.nio.NioSocketChannel")); @@ -115,6 +117,9 @@ NativeImageConfigBuildItem build( .addRuntimeReinitializedClass("io.netty.util.internal.PlatformDependent0") .addNativeImageSystemProperty("io.netty.leakDetection.level", "DISABLED"); + // Also set io.netty.noUnsafe at runtime + systemProperties.produce(new SystemPropertyBuildItem("io.netty.noUnsafe", "true")); + if (QuarkusClassLoader.isClassPresentAtRuntime("io.netty.handler.codec.http.HttpObjectEncoder")) { builder .addRuntimeInitializedClass("io.netty.handler.codec.http.HttpObjectEncoder") @@ -163,8 +168,7 @@ NativeImageConfigBuildItem build( log.debug("Not registering Netty native kqueue classes as they were not found"); } - return builder //TODO: make configurable - .build(); + return builder.build(); } @BuildStep