Skip to content
This repository was archived by the owner on Sep 26, 2023. It is now read-only.
This repository was archived by the owner on Sep 26, 2023. It is now read-only.

GraalVM native image and netty's Slf4JLoggerFactory from gax-grpc/native-image.properties #1696

Description

@edudar

I'm trying to build a native image that uses gcloud java libraries. The first issue I encountered is

No instances of io.grpc.netty.shaded.io.netty.util.internal.logging.Slf4JLoggerFactory 
are allowed in the image heap as this class should be initialized at image runtime.

Fatal error: org.graalvm.compiler.debug.GraalError: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: No instances of io.grpc.netty.shaded.io.netty.util.internal.logging.Slf4JLoggerFactory are allowed in the image heap as this class should be initialized at image runtime. Object has been initialized by the io.grpc.netty.shaded.io.netty.channel.ChannelOption class initializer with a trace: 
 	at io.grpc.netty.shaded.io.netty.util.internal.logging.Slf4JLoggerFactory.<init>(Slf4JLoggerFactory.java:42)
	at io.grpc.netty.shaded.io.netty.util.internal.logging.Slf4JLoggerFactory.<clinit>(Slf4JLoggerFactory.java:33)
	at io.grpc.netty.shaded.io.netty.util.internal.logging.InternalLoggerFactory.useSlf4JLoggerFactory(InternalLoggerFactory.java:62)
	at io.grpc.netty.shaded.io.netty.util.internal.logging.InternalLoggerFactory.newDefaultFactory(InternalLoggerFactory.java:42)
	at io.grpc.netty.shaded.io.netty.util.internal.logging.InternalLoggerFactory.getDefaultFactory(InternalLoggerFactory.java:111)
	at io.grpc.netty.shaded.io.netty.util.internal.logging.InternalLoggerFactory.getInstance(InternalLoggerFactory.java:134)
	at io.grpc.netty.shaded.io.netty.util.internal.logging.InternalLoggerFactory.getInstance(InternalLoggerFactory.java:127)
	at io.grpc.netty.shaded.io.netty.util.internal.PlatformDependent.<clinit>(PlatformDependent.java:81)
	at io.grpc.netty.shaded.io.netty.util.ConstantPool.<init>(ConstantPool.java:34)
	at io.grpc.netty.shaded.io.netty.channel.ChannelOption$1.<init>(ChannelOption.java:36)
	at io.grpc.netty.shaded.io.netty.channel.ChannelOption.<clinit>(ChannelOption.java:36)
.  To fix the issue mark io.grpc.netty.shaded.io.netty.util.internal.logging.Slf4JLoggerFactory for build-time initialization with --initialize-at-build-time=io.grpc.netty.shaded.io.netty.util.internal.logging.Slf4JLoggerFactory or use the the information from the trace to find the culprit and --initialize-at-run-time=<culprit> to prevent its instantiation.

when I tried to apply the suggested fix I get another error that points to gax-grpc:

Error: Incompatible change of initialization policy for io.grpc.netty.shaded.io.netty.util.internal.logging.Slf4JLoggerFactory: 
trying to change RUN_TIME from 'META-INF/native-image/com.google.api/gax-grpc/native-image.properties' in 'file:///.../com.google.api/gax-grpc/2.18.1/a3f2cca007aaa26868b4750e56b0af7ae63f5e3c/gax-grpc-2.18.1.jar' with 'io.grpc.netty.shaded.io.netty.util.internal.logging.Slf4JLoggerFactory' 
to BUILD_TIME from command line with 'io.grpc.netty.shaded.io.netty.util.internal.logging.Slf4JLoggerFactory'
com.oracle.svm.core.util.UserError$UserException: 
Incompatible change of initialization policy for io.grpc.netty.shaded.io.netty.util.internal.logging.Slf4JLoggerFactory: trying to change RUN_TIME from 'META-INF/native-image/com.google.api/gax-grpc/native-image.properties' 
in 'file:///.../com.google.api/gax-grpc/2.18.1/a3f2cca007aaa26868b4750e56b0af7ae63f5e3c/gax-grpc-2.18.1.jar' with 'io.grpc.netty.shaded.io.netty.util.internal.logging.Slf4JLoggerFactory' to BUILD_TIME from command line with 'io.grpc.netty.shaded.io.netty.util.internal.logging.Slf4JLoggerFactory'
	at com.oracle.svm.core.util.UserError.abort(UserError.java:72)
	at com.oracle.svm.hosted.classinitialization.ClassInitializationConfiguration.insertRec(ClassInitializationConfiguration.java:102)

implementation platform("com.google.cloud:spring-cloud-gcp-dependencies:3.3.0")
implementation group: 'com.google.cloud', name: 'spring-cloud-gcp-starter-trace'
implementation "com.google.api:gax:2.18.1"
implementation "com.google.api:gax-grpc:2.18.1"

Metadata

Metadata

Assignees

Labels

priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions