Skip to content

Commit

Permalink
WIP: avoid unregistered reflective and resource accesses
Browse files Browse the repository at this point in the history
  • Loading branch information
zakkak committed Jan 25, 2024
1 parent 11a8e26 commit 5919813
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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", "<init>",
java.security.SecureRandomParameters.class);
}

@BuildStep
void registerNativeImageResources(BuildProducer<NativeImageResourceBuildItem> 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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -81,6 +82,7 @@ public SystemPropertyBuildItem setNettyMachineId() {
NativeImageConfigBuildItem build(
NettyBuildTimeConfig config,
BuildProducer<ReflectiveClassBuildItem> reflectiveClass,
BuildProducer<ReflectiveMethodBuildItem> reflectiveMethod,
List<MinNettyAllocatorMaxOrderBuildItem> minMaxOrderBuildItems) {

reflectiveClass.produce(ReflectiveClassBuildItem.builder("io.netty.channel.socket.nio.NioSocketChannel")
Expand Down Expand Up @@ -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", "<init>", long.class, long.class));

if (QuarkusClassLoader.isClassPresentAtRuntime("io.netty.buffer.UnpooledByteBufAllocator")) {
builder.addRuntimeReinitializedClass("io.netty.buffer.UnpooledByteBufAllocator")
.addRuntimeReinitializedClass("io.netty.buffer.Unpooled")
Expand Down

0 comments on commit 5919813

Please sign in to comment.