From b7ca95f12dfe8287c133e09534be1fc46882ce6c Mon Sep 17 00:00:00 2001 From: Mridula <66699525+mpeddada1@users.noreply.github.com> Date: Wed, 1 Feb 2023 17:03:08 -0500 Subject: [PATCH] fix(java): initialize netty-shaded at run-time and add reflection configurations for netty classes (#1290) * fix(java): initialize netty-shaded at run-time and add reflection configurations for netty classes --- .../grpc/nativeimage/GrpcNettyFeature.java | 20 ++++++++++ .../gax-grpc/native-image.properties | 3 +- .../gax-grpc/reflect-config.json | 39 +++++++++++++++++++ 3 files changed, 61 insertions(+), 1 deletion(-) diff --git a/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/nativeimage/GrpcNettyFeature.java b/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/nativeimage/GrpcNettyFeature.java index 23db568b72..bbd899b284 100644 --- a/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/nativeimage/GrpcNettyFeature.java +++ b/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/nativeimage/GrpcNettyFeature.java @@ -85,6 +85,26 @@ private static void loadGrpcNettyClasses(BeforeAnalysisAccess access) { registerClassForReflection(access, "io.grpc.netty.shaded.io.netty.channel.DefaultFileRegion"); registerClassForReflection( access, "io.grpc.netty.shaded.io.netty.channel.unix.PeerCredentials"); + registerClassForReflection( + access, "io.grpc.netty.shaded.io.netty.channel.DefaultChannelPipeline"); + registerClassForReflection( + access, "io.grpc.netty.shaded.io.grpc.netty.WriteBufferingAndExceptionHandler"); + registerClassForReflection( + access, "io.grpc.netty.shaded.io.netty.channel.ProtocolNegotiators"); + registerClassForReflection(access, "io.grpc.netty.shaded.io.netty.handler.ssl.SslHandler"); + registerClassForReflection(access, "io.grpc.netty.shaded.io.grpc.netty.NettyClientHandler"); + registerClassForReflection( + access, "io.grpc.netty.shaded.io.netty.channel.DefaultChannelPipeline$HeadContext"); + registerClassForReflection( + access, "io.grpc.netty.shaded.io.netty.channel.DefaultChannelPipeline$TailContext"); + registerClassForReflection( + access, "io.grpc.netty.shaded.io.grpc.netty.ProtocolNegotiators$WaitUntilActiveHandler"); + registerClassForReflection( + access, "io.grpc.netty.shaded.io.grpc.netty.ProtocolNegotiators$ClientTlsHandler"); + registerClassForReflection( + access, "io.grpc.netty.shaded.io.grpc.netty.ProtocolNegotiators$GrpcNegotiationHandler"); + registerClassForReflection( + access, "io.grpc.netty.shaded.io.netty.channel.ChannelHandlerMask"); // Epoll Libraries registerClassForReflection(access, "io.grpc.netty.shaded.io.netty.channel.epoll.Epoll"); diff --git a/gax-java/gax-grpc/src/main/resources/META-INF/native-image/com.google.api/gax-grpc/native-image.properties b/gax-java/gax-grpc/src/main/resources/META-INF/native-image/com.google.api/gax-grpc/native-image.properties index b66e70603f..262f5d17a2 100644 --- a/gax-java/gax-grpc/src/main/resources/META-INF/native-image/com.google.api/gax-grpc/native-image.properties +++ b/gax-java/gax-grpc/src/main/resources/META-INF/native-image/com.google.api/gax-grpc/native-image.properties @@ -9,7 +9,8 @@ Args=--add-opens=java.base/java.time=ALL-UNNAMED \ io.grpc.netty.shaded.io.netty.channel.epoll,\ io.grpc.netty.shaded.io.netty.channel.unix,\ io.grpc.netty.shaded.io.netty.handler.ssl,\ - io.grpc.internal.RetriableStream \ + io.grpc.internal.RetriableStream,\ + io.grpc.netty.shaded.io.netty \ --features=com.google.api.gax.grpc.nativeimage.ProtobufMessageFeature,\ com.google.api.gax.grpc.nativeimage.GrpcNettyFeature \ -H:-RunReachabilityHandlersConcurrently \ No newline at end of file diff --git a/gax-java/gax-grpc/src/main/resources/META-INF/native-image/com.google.api/gax-grpc/reflect-config.json b/gax-java/gax-grpc/src/main/resources/META-INF/native-image/com.google.api/gax-grpc/reflect-config.json index 69f24071df..463a4bb1d5 100644 --- a/gax-java/gax-grpc/src/main/resources/META-INF/native-image/com.google.api/gax-grpc/reflect-config.json +++ b/gax-java/gax-grpc/src/main/resources/META-INF/native-image/com.google.api/gax-grpc/reflect-config.json @@ -283,5 +283,44 @@ "name": "selectedKeys" } ] + }, + { + "name" : "com.google.auth.oauth2.ServiceAccountCredentials", + "allDeclaredConstructors" : true, + "allPublicConstructors" : true, + "allDeclaredMethods" : true, + "allPublicMethods" : true, + "allDeclaredFields" : true, + "allPublicFields" : true, + "queryAllPublicConstructors" : true, + "queryAllDeclaredConstructors" : true, + "queryAllPublicMethods" : true, + "queryAllDeclaredMethods" : true + }, + { + "name" : "org.apache.commons.pool2.impl.DefaultEvictionPolicy", + "allDeclaredConstructors" : true, + "allPublicConstructors" : true, + "allDeclaredMethods" : true, + "allPublicMethods" : true, + "allDeclaredFields" : true, + "allPublicFields" : true, + "queryAllPublicConstructors" : true, + "queryAllDeclaredConstructors" : true, + "queryAllPublicMethods" : true, + "queryAllDeclaredMethods" : true + }, + { + "name" : "java.nio.channels.spi.SelectorProvider", + "allDeclaredConstructors" : true, + "allPublicConstructors" : true, + "allDeclaredMethods" : true, + "allPublicMethods" : true, + "allDeclaredFields" : true, + "allPublicFields" : true, + "queryAllPublicConstructors" : true, + "queryAllDeclaredConstructors" : true, + "queryAllPublicMethods" : true, + "queryAllDeclaredMethods" : true } ]