Just switching from mockito-core to mockito-inline (4.11.0), without any code changes, causes logback-classic (1.2.11) to throw
Caused by: java.lang.NullPointerException: Cannot read the array length because "throwableSuppressed" is null
at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:99)
at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:62)
at ch.qos.logback.classic.spi.LoggingEvent.<init>(LoggingEvent.java:119)
at ch.qos.logback.classic.Logger.buildLoggingEventAndAppend(Logger.java:419)
at ch.qos.logback.classic.Logger.filterAndLog_0_Or3Plus(Logger.java:383)
at ch.qos.logback.classic.Logger.warn(Logger.java:704)
the log line is
LOG.warn(
"{} while registering RIC {}, will retry once: {}",
oe.getClass().getSimpleName(), ric, oe.toString(), oe);
Any ideas how to fix this?
Changing the args to
oe.getClass().getSimpleName(), ric, oe.toString()
works around the issue but you loose the stacktrace in the logs, and I'd hate to loose that in production just to work around an issue in the tests.
Changing the args to
oe.getClass().getSimpleName(), ric, oe
or oe.getClass().getSimpleName(), ric, oe, oe
does not work.
The answer involves the fact that it is a mocked exception (which I have to do because the exception I need is from a 3rd party library and they don't expose a way to create a real one).
With
mockito-coreand no explicit mocking of thegetSuppressed()method it returnsThrowable[0]but with
mockito-inlineit returnsnull.I am certainly surprised that just changing that dependency affects what is returned by default there, but it can be solved by explicitly mocking it out like