You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I understand that in this case I should have passed the TestKit to the ScalaTestWithActorTestKit constructor (which I do now), but having the ability to override testKit, makes it a possible usage for other people too.
The text was updated successfully, but these errors were encountered:
I don't think this is generally solvable due to how trait initialization works in Scala 2, long story short trait composition in Scala 2 is not commutative which means that the order of when you mix in traits can effect initialization which can lead to NullPointerException in cases like this. For these reason its not really Pekko specific.
The solution to this problem is to use lazy val/def when you override the field. Also afaik this is not an issue in Scala 3 where the compiler will re-order the fields in traits to make sure its initialized correctly.
While migrating a project to Pekko, I noticed that some of the tests started failing with
NullPointerException
s.On further investigation, it was because I was overriding the TestKit inside those tests.
Here's a simple reproducer:
I think the issue seems to be this line, where the
val
is not lazy, leading to a NullPointerException.https://github.com/apache/incubator-pekko/blob/28314e679885519f6458ebf10f9a181d5299c83a/actor-testkit-typed/src/main/scala/org/apache/pekko/actor/testkit/typed/scaladsl/ScalaTestWithActorTestKit.scala#L94
I understand that in this case I should have passed the
TestKit
to theScalaTestWithActorTestKit
constructor (which I do now), but having the ability to overridetestKit
, makes it a possible usage for other people too.The text was updated successfully, but these errors were encountered: