Description
Description
When upgrading an Android Application which has a transitive dependency on Log4j from log4j-core 2.21.1 to 2.22.0, it fails with an exception because it seems the method AccessController.doPrivileged() with the required parameters is not available on Android, but calls to it are introduced in LoaderUtil now via commit 80de816
This prevents us from upgrading log4j when including any Java libraries which depend on log4j-core in an Android application.
Is it possible to not introduce these changes in the 2.x series? The commit-message sounds like this was sort of "let's backport some stuff from 3.x branches".
Configuration
Version: 2.22.0
Operating system: Android application with min SDK Level 26
JDK: Android
Logs
java.lang.NoSuchMethodError: No static method doPrivileged(Ljava/security/PrivilegedAction;Ljava/security/AccessControlContext;[Ljava/security/Permission;)Ljava/lang/Object; in class Ljava/security/AccessController; or its super classes (declaration of 'java.security.AccessController' appears in /system/framework/core-oj.jar)
at org.apache.logging.log4j.util.LoaderUtil.getThreadContextClassLoader(LoaderUtil.java:155)
at org.apache.logging.log4j.util.LoaderUtil.findUrlResources(LoaderUtil.java:473)
at org.apache.logging.log4j.util.LoaderUtil.findResources(LoaderUtil.java:462)
at org.apache.logging.log4j.util.PropertyFilePropertySource.loadPropertiesFile(PropertyFilePropertySource.java:45)
at org.apache.logging.log4j.util.PropertyFilePropertySource.<init>(PropertyFilePropertySource.java:37)
at org.apache.logging.log4j.util.PropertiesUtil.<init>(PropertiesUtil.java:84)
at org.apache.logging.log4j.util.PropertiesUtil.<init>(PropertiesUtil.java:80)
at org.apache.logging.log4j.status.StatusLogger.<clinit>(StatusLogger.java:76)
at org.apache.logging.log4j.status.StatusLogger.getLogger(StatusLogger.java:149)
at org.apache.logging.log4j.LogManager.<clinit>(LogManager.java:60)
at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:610)
at org.dstadler.poiandroidtest.poitest.ApplicationTest.<clinit>(ApplicationTest.java:17)
Reproduction
Can only be reproduced in Android applications using the Emulator.
There is a sample Android application "poi-on-android" which shows the issue:
- See the following branch for the test-failure with 2.22.0: https://github.com/centic9/poi-on-android/tree/exception_with_log4j_2_22_0 => Fails to run tests via Github Actions, e.g. https://github.com/centic9/poi-on-android/actions/runs/7331541081/job/19964336406
- See the following commit for the same sources except the newer log4j: centic9/poi-on-android@bbea240 => Successfully runs tests via Github Actions, e.g. https://github.com/centic9/poi-on-android/actions/runs/7331536562/job/19964325253