smithy-lang / smithy-kotlin

Smithy code generator for Kotlin (in development)
Apache License 2.0
79 stars 26 forks source link

fix: Prevent NoSuchMethodError when a slf4j1 logger is used with slf4j2 in the classpath #981

Closed NatanLifshitz closed 11 months ago

NatanLifshitz commented 11 months ago

The useSlf4j2x flag is changed to be more precise and check if the Logger instance actually supports slf4j2 methods, as opposed to checking if slf4j2 exists in the classpath which fails with a slf4j1 logger in a slf4j2 classpath.

A test project exists to demonstrate this issue. It does not pass with the old code, but does pass with this PR's code. I will note it was difficult as hell to reproduce in a vacuum.

Issue \

https://github.com/awslabs/aws-sdk-kotlin/issues/1077

Description of changes

Gradle overrides most of the slf4j classes, but it overrides it with a slf4j1 API, which doesn't support slf4j2 methods. This means if you tried to run the AWS SDK for Kotlin in a Gradle buildscript, it would use Gradle's slf4fj1 logger, and the AWS SDK was probably pulling slf4j2 itself into the classpath, causing this problem.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

sonarcloud[bot] commented 11 months ago

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