Marian Schubert
07/29/2022, 9:42 AM@Transactional
) in following code:
class MyBoolean(var value: Boolean) {
fun get(): Boolean = value
}
abstract class Foo {
private val _hasError = MyBoolean(false) // <- line 16
val hasError: Boolean get() = _hasError.get()
}
@Component
class MyFoo : Foo() {
@Transactional
fun doFoo() {
}
}
class FooTest : SpringTest() {
@Autowired
lateinit var foo: MyFoo
@Test
fun `is null`() {
assertThat(foo.hasError).isFalse // <- line 33
foo.doFoo()
}
}
code/test above throws exception
java.lang.NullPointerException: Cannot invoke "com.bitsafe.behi.admin.projections.MyBoolean.get()" because "this._hasError" is null
at Foo.getHasError(FooTest.kt:16)
at <http://FooTest.is|FooTest.is> null(FooTest.kt:33)
which doesn't make sense as _hasError
should never be null
? If I remove @Transactional
from doFoo
method everything works as expected. What's going on?
BTW problem also disappears if I put stuff from abstract class Foo
directly into class MyFoo
(which I don't want).Chris Lee
07/29/2022, 2:37 PMfoo
is declared as lateinit - but not initialized.Marian Schubert
07/29/2022, 2:46 PMChris Lee
07/29/2022, 2:46 PMMarian Schubert
07/29/2022, 2:49 PMprivate val _hasError
to open val _hasError
it worksChris Lee
07/29/2022, 2:49 PMMarian Schubert
07/29/2022, 2:50 PMsreich
08/03/2022, 4:31 PM