JetBrains / lincheck

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

internal lincheck NPE in monitor wait deadlock #125

Closed btwilk closed 1 year ago

btwilk commented 1 year ago

The following lincheck test deadlocks on a monitor wait, but lincheck fails to report the deadlock and rather throws an internal NPE.

import org.jetbrains.kotlinx.lincheck.annotations.Operation
import org.jetbrains.kotlinx.lincheck.check
import org.jetbrains.kotlinx.lincheck.strategy.managed.modelchecking.ModelCheckingOptions
import org.junit.jupiter.api.Test

class LinTest {

    private val guard = Object()

    @Operation
    fun foo() {
        synchronized(guard) {
            guard.wait()
        }
    }

    @Test
    fun test() = ModelCheckingOptions().actorsBefore(0).check(this::class)
}

Output:

java.lang.NullPointerException
    at org.jetbrains.kotlinx.lincheck.strategy.managed.MonitorTracker.releaseMonitor(ManagedStrategy.kt:867)
    at org.jetbrains.kotlinx.lincheck.strategy.managed.ManagedStrategy.beforeLockRelease$lincheck(ManagedStrategy.kt:473)
    at LinTest.foo(LinTest.kt:12)
    at org.jetbrains.kotlinx.lincheck.runner.TestThreadExecution38.run(Unknown Source)
    at org.jetbrains.kotlinx.lincheck.runner.FixedActiveThreadsExecutor$testThreadRunnable$1.run(FixedActiveThreadsExecutor.kt:173)
    at java.base/java.lang.Thread.run(Thread.java:1589)
alefedor commented 1 year ago

@btwilk Hi! Thank you for this test. A fix will be present in the next LinCheck update