JetBrains / lincheck

Framework for testing concurrent data structures
Mozilla Public License 2.0
572 stars 33 forks source link

log4j2 incompatibility #133

Closed btwilk closed 2 months ago

btwilk commented 1 year ago

lincheck version: 2.15 log4j version: 2.17.2

In my system under test I have

private val log: Logger = LogManager.getLogger("SystemUnderTestKt")

When I run a lincheck test I get

java.lang.NoClassDefFoundError: Could not initialize class org.apache.logging.log4j.util.PropertiesUtil
    at org.apache.logging.log4j.status.StatusLogger.<clinit>(StatusLogger.java:78)
    at org.apache.logging.log4j.LogManager.<clinit>(LogManager.java:61)
    at SystemUnderTestKt.<clinit>(SystemUnderTest.kt:17)
    at LinTest.<init>(LinTest.kt:111)

Ignoring log4j classes with .addGuarantee(forClasses(LogManager::class, Logger::class).allMethods().ignore()) doesn't help.

Non-lincheck unit tests for the system under test work fine.

alefedor commented 1 year ago

Hi @btwilk !

It seems log4j2 had this kind of problem before and the problem should have been fixed for your version. https://issues.apache.org/jira/browse/LOG4J2-2266

This happens because lincheck uses a custom classloader for byte-code transformation and log4j has a class that can not be loaded in this way. In general, we can not fix this. If a class can not be loaded with a custom classloader, then its byte-code can not be transformed.

ignore guarantee makes lincheck ignore what happens in the class, but does not remove method calls from byte-code. We can potentially make it not transform a class, but this will introduce new problems. For example, when a superclass A is transformed but the class B extends A itself is not, this will lead to a JVM failure when trying to do val a: A = B()

ndkoval commented 1 year ago

We will eliminate custom class loaders in Lincheck, which should solve the issue.

ndkoval commented 4 months ago

Hi, @btwilk! It has taken a while to address the issue, but the recent 2.30 release should've fixed it. Could you please check?

ndkoval commented 2 months ago

@btwilk I'm closing this issue, as it should be fixed now. Please reopen it if you are still facing the bug.