'Log4J2 AppenderLoggingException NoSuchMethodError StackLocatorUtil.getCurrentStackTrace()

As soon as an exception/error occurs and is supposed to be logged, I get the following error/stack trace:

org.apache.logging.log4j.core.appender.AppenderLoggingException: java.lang.NoSuchMethodError: 'java.util.Deque org.apache.logging.log4j.util.StackLocatorUtil.getCurrentStackTrace()'
   at org.apache.logging.log4j.core.config.AppenderControl.tryCallAppender(AppenderControl.java:165)
   at org.apache.logging.log4j.core.config.AppenderControl.callAppender0(AppenderControl.java:134)
   at org.apache.logging.log4j.core.config.AppenderControl.callAppenderPreventRecursion(AppenderControl.java:125)
   at org.apache.logging.log4j.core.config.AppenderControl.callAppender(AppenderControl.java:89)
   at org.apache.logging.log4j.core.config.LoggerConfig.callAppenders(LoggerConfig.java:675)
   at org.apache.logging.log4j.core.config.LoggerConfig.processLogEvent(LoggerConfig.java:633)
   at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:616)
   at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:552)
   at org.apache.logging.log4j.core.config.AwaitCompletionReliabilityStrategy.log(AwaitCompletionReliabilityStrategy.java:82)
   at org.apache.logging.log4j.core.Logger.log(Logger.java:161)
   at org.apache.logging.log4j.spi.AbstractLogger.tryLogMessage(AbstractLogger.java:2205)
   at org.apache.logging.log4j.spi.AbstractLogger.logMessageTrackRecursion(AbstractLogger.java:2159)
   at org.apache.logging.log4j.spi.AbstractLogger.logMessageSafely(AbstractLogger.java:2142)
   at org.apache.logging.log4j.spi.AbstractLogger.logMessage(AbstractLogger.java:2017)
   at org.apache.logging.log4j.spi.AbstractLogger.logIfEnabled(AbstractLogger.java:1983)
   at org.apache.logging.log4j.spi.AbstractLogger.fatal(AbstractLogger.java:1063)

the next at is whatever called Logger#fatal/error(String,Throwable)

Java 11, Log4J 2.17.2 (-core and -api), project built using Gradle. removing Multi-Release: true from build.gradle doesn't seem to fix the issue (only adds the, to be expected, Reflection.getCallerClass() warning)

What am I missing?



Solution 1:[1]

Turns out a library had the dependency Log4J-api 2.17.1 (but not -core), my gradle file specified Log4J-core 2.17.2 so the older -api version overrid the latest one. Apparently, from 2.17.1 to .2, StackLocatorUtil.getCurrentStackTrace()'s return was changed from Stack to Deque.

Solution 2:[2]

Looks like the missing method 'org.apache.logging.log4j.util.StackLocatorUtil.getCurrentStackTrace()' is in the log4j-api jar and is called by the AppenderControl class from log4j-core jar.

One possible issue may be that you have both jars on "compile classpath" but only the log4j-core on "runtime classpath". Make sure your gradle configuration does not use the log4j-api as a "compile only" dependency.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Jakubeeee