neboskreb commented on PR #3638: URL: https://github.com/apache/logging-log4j2/pull/3638#issuecomment-2848388794
> Thanks a lot! Now the Android support is almost as good as the JVM support! It was my honour to contribute! > IIRC there is still one location-related feature that breaks on Android: `LogManager.getLogger()` will fail, since the Java 8 version of `StackLocator` relies on the absent `sun.reflect.Reflection` class and Android does not support Multi-Release JARs, so it doesn't use the Java 11 version of `StackLocator`. > > If you know of a smart way to fix that, let me know. If you mean [this place](https://github.com/apache/logging-log4j2/blob/db0360d4ce1e5ba5a3d9409da79695f54e857857/log4j-api/src/main/java/org/apache/logging/log4j/LogManager.java#L543) then, in my humble opinion, the culprit is lack of flexibility in `StackLocatorUtil`. If I was to refactor it, I would employ the Strategy pattern in `StackLocatorUtil` rather than adding more code to `StackLocator`. This way, while initializing `StackLocatorUtil`, I would inject the existing `StackLocator` for JVM platforms and `AndroidStackLocator` for Android. The easiest way to fill the stack is `new Throwable().getStackTrace()`, which is already used this way in `StackLocator#calcLocation` - though this can be slow. I'm not aware of faster ways - I'm not deep enough into Java mechanics, sorry. I see 2 implementations of `StackLocator`, with the newer one relying on `StackWalker`. It is [available on Android](https://developer.android.com/reference/java/lang/StackWalker), though on the most recent versions only (Android 14+). This way, the `StackLocator` strategy can be used on newer devices and on JVM while falling back to the slower `AndroidStackLocator` on older devices. Not sure how this solution aligns with your current packaging strategy (because you mentioned multi-release JAR). Take it as a wild idea. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org