Skip to content

Regression in Log4j 2.22.0 on Android because of changes to getThreadContextClassLoader() in LoaderUtil #2129

Closed
@centic9

Description

@centic9

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:

Metadata

Metadata

Assignees

Labels

bugIncorrect, unexpected, or unintended behavior of existing coderuntimeSpecific to the runtime environment

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions