Log4J2 AppenderLoggingException NoSuchMethodError StackLocatorUtil.getCurrentStackTrace()
Asked Answered
F

2

11

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?

Farmyard answered 3/4, 2022 at 1:45 Comment(1)
Please provide enough code so others can better understand or reproduce the problem.Noto
F
19

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.

Farmyard answered 3/4, 2022 at 19:36 Comment(1)
Dang! Just got caught by this one - updated lib to 2.17.2 and all is well again!Callan
T
0

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.

Toxicogenic answered 3/4, 2022 at 19:29 Comment(1)
yes and no. local dependency that had only -api but an older version. The method is present in both versions, but with a different signature (return value). Found it out JUST before you commentedFarmyard

© 2022 - 2024 — McMap. All rights reserved.