Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Builder<T>.isNotNull() fails with IllegalArgumentException inside and{ .... } #204

MartinHaeusler opened this issue Jan 31, 2020 · 2 comments
🐛 bug


Copy link

@MartinHaeusler MartinHaeusler commented Jan 31, 2020


this one is similar to #203, but this time it's about the isNotNull() assertion. They might be related though.

Minimal example:

    fun striktNullTest() {
        class Person(val name: String, val friend: Person?)
        // imagine we get this from an API which is nullable
        val p: Person? = Person("John", null)

        expectThat(p).isNotNull().and {
            get { name }.isEqualTo("John")
            get { friend }.isNotNull().and {  // this isNotNull() allows the following code to continue
                get { name }.isEqualTo("Jack")

Expected: the usual nice strikt assertion failure message.


java.lang.IllegalArgumentException: Parameter specified as non-null is null: method org.example.StriktTest$striktNullTest$1$3$1.invoke, parameter $receiver

	at org.example.StriktTest$striktNullTest$1$3$1.invoke(StriktTest.kt)
	at org.example.StriktTest$striktNullTest$1$3$1.invoke(StriktTest.kt:8)
	at strikt.internal.AssertionBuilder.get(AssertionBuilder.kt:92)
	at strikt.api.Assertion$Builder$DefaultImpls.get(Assertion.kt:233)
	at strikt.api.DescribeableBuilder$DefaultImpls.get(DescribeableBuilder.kt)
	at strikt.internal.AssertionBuilder.get(AssertionBuilder.kt:11)
	at org.example.StriktTest$striktNullTest$1$3.invoke(StriktTest.kt:20)
	at org.example.StriktTest$striktNullTest$1$3.invoke(StriktTest.kt:8)
	at strikt.internal.AssertionBuilder.and(AssertionBuilder.kt:37)
	at org.example.StriktTest$striktNullTest$1.invoke(StriktTest.kt:19)
	at org.example.StriktTest$striktNullTest$1.invoke(StriktTest.kt:8)
	at strikt.internal.AssertionBuilder.and(AssertionBuilder.kt:37)
	at org.example.StriktTest.striktNullTest(StriktTest.kt:17)

What I gather from this is that .isNotNull() allows the methods chained after it to continue execution when it's inside an and{ ... } block. Then, for the following methods, the receiver is (of course) null, because the .isNotNul() did not terminate the execution of the chain. The result is a runtime exception as shown above during the construction of the assertion.

@robfletcher robfletcher added the 🐛 bug label Feb 8, 2020
Copy link

@robfletcher robfletcher commented Feb 9, 2020

Appreciate the reports. This and #203 are fixed in the latest release. I added your test cases to

Copy link

@MartinHaeusler MartinHaeusler commented Feb 9, 2020

That's great, thanks! Glad to hear you've found those test cases useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
🐛 bug
None yet

No branches or pull requests

2 participants