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

fix: remove runtime initialization of logger classes #1733

Merged
merged 1 commit into from
Jul 12, 2022
Merged

Conversation

mpeddada1
Copy link
Contributor

Fixes #1696

gax-grpc transitively invokes the io.netty.util.internal.PlatformDependent class which leads to InternalLoggerFactory being initialized. InternalLoggerFactory . As described here, InternalLoggerFactory first chooses Slf4jLoggerFactory as the default logger factory and if slf4j is not present then it chooses Log4JLoggerFactory and so on. This results in io.grpc.netty.shaded.io.netty.util.internal.logging.Slf4JLoggerFactory and io.grpc.netty.shaded.io.netty.util.internal.logging.Log4JLogger being initialized and can sometimes lead to the following warning by graal during native image compilation (when slf4j is not present on the classpath):

Warning: class initialization of class io.grpc.netty.shaded.io.netty.util.internal.logging.Slf4JLoggerFactory failed with exception java.lang.NoClassDefFoundError: Could not initialize class io.grpc.netty.shaded.io.netty.util.internal.logging.Slf4JLoggerFactory. This class will be initialized at run time because option --allow-incomplete-classpath is used for image building. Use the option --initialize-at-run-time=io.grpc.netty.shaded.io.netty.util.internal.logging.Slf4JLoggerFactory to explicitly request delayed initialization of this class.

To avoid this warning, we initially followed the instructions to initialize these classes at runtime. While this behaves fine when there is no slf4j or log4j dependency on the classpath, this breaks behavior when these logging dependencies are actually added.

Reproducer: https://github.com/mpeddada1/simple-netty-test/blob/main/README.md

@mpeddada1 mpeddada1 requested review from a team as code owners July 11, 2022 22:27
@mpeddada1 mpeddada1 requested review from suztomo and meltsufin July 11, 2022 22:27
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@mpeddada1 mpeddada1 merged commit ccaf265 into main Jul 12, 2022
@mpeddada1 mpeddada1 deleted the fix-netty-slf4j branch July 12, 2022 14:33
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GraalVM native image and netty's Slf4JLoggerFactory from gax-grpc/native-image.properties
2 participants