From 5919813552e5ee9fb998cf89c82aafcc6af06f31 Mon Sep 17 00:00:00 2001 From: Foivos Zakkak Date: Thu, 25 Jan 2024 09:30:35 +0200 Subject: [PATCH] WIP: avoid unregistered reflective and resource accesses --- .../quarkus/deployment/QuarkusProcessor.java | 26 +++++++++++++++++++ .../netty/deployment/NettyProcessor.java | 5 ++++ 2 files changed, 31 insertions(+) create mode 100644 core/deployment/src/main/java/io/quarkus/deployment/QuarkusProcessor.java diff --git a/core/deployment/src/main/java/io/quarkus/deployment/QuarkusProcessor.java b/core/deployment/src/main/java/io/quarkus/deployment/QuarkusProcessor.java new file mode 100644 index 00000000000000..c293d93fdb9fe9 --- /dev/null +++ b/core/deployment/src/main/java/io/quarkus/deployment/QuarkusProcessor.java @@ -0,0 +1,26 @@ +package io.quarkus.deployment; + +import static io.smallrye.config.SmallRyeConfigBuilder.META_INF_MICROPROFILE_CONFIG_PROPERTIES; + +import io.quarkus.deployment.annotations.BuildProducer; +import io.quarkus.deployment.annotations.BuildStep; +import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem; +import io.quarkus.deployment.builditem.nativeimage.ReflectiveMethodBuildItem; + +public class QuarkusProcessor { + + @BuildStep + ReflectiveMethodBuildItem registerReflectiveMethods() { + // Called reflectively when generating quarkus.uuid + return new ReflectiveMethodBuildItem("sun.security.provider.NativePRNG", "", + java.security.SecureRandomParameters.class); + } + + @BuildStep + void registerNativeImageResources(BuildProducer resources) { + // Accessed by io.quarkus.runtime.configuration.ApplicationPropertiesConfigSourceLoader.InClassPath.getConfigSources + resources.produce(new NativeImageResourceBuildItem("application.properties")); + // Accessed by io.smallrye.config.SmallRyeConfigBuilder.getDefaultSources + resources.produce(new NativeImageResourceBuildItem(META_INF_MICROPROFILE_CONFIG_PROPERTIES)); + } +} 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 11801f0547d60b..a5e3ca8472c7dc 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 @@ -27,6 +27,7 @@ import io.quarkus.deployment.builditem.nativeimage.NativeImageConfigBuildItem; import io.quarkus.deployment.builditem.nativeimage.NativeImageSystemPropertyBuildItem; import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem; +import io.quarkus.deployment.builditem.nativeimage.ReflectiveMethodBuildItem; import io.quarkus.deployment.builditem.nativeimage.RuntimeInitializedClassBuildItem; import io.quarkus.deployment.builditem.nativeimage.RuntimeReinitializedClassBuildItem; import io.quarkus.deployment.builditem.nativeimage.UnsafeAccessedFieldBuildItem; @@ -81,6 +82,7 @@ public SystemPropertyBuildItem setNettyMachineId() { NativeImageConfigBuildItem build( NettyBuildTimeConfig config, BuildProducer reflectiveClass, + BuildProducer reflectiveMethod, List minMaxOrderBuildItems) { reflectiveClass.produce(ReflectiveClassBuildItem.builder("io.netty.channel.socket.nio.NioSocketChannel") @@ -165,6 +167,9 @@ NativeImageConfigBuildItem build( builder.addRuntimeReinitializedClass("io.netty.util.internal.PlatformDependent") .addRuntimeReinitializedClass("io.netty.util.internal.PlatformDependent0"); + // Called reflectively during io.netty.util.internal.PlatformDependent0 class initialization + reflectiveMethod.produce(new ReflectiveMethodBuildItem("java.nio.DirectByteBuffer", "", long.class, long.class)); + if (QuarkusClassLoader.isClassPresentAtRuntime("io.netty.buffer.UnpooledByteBufAllocator")) { builder.addRuntimeReinitializedClass("io.netty.buffer.UnpooledByteBufAllocator") .addRuntimeReinitializedClass("io.netty.buffer.Unpooled")