Closed xeruf closed 6 years ago
I have experienced this problem before and it is related to the initialization dependecy order. In short guide requires application to be initialized, but something causes guide to initialize before application is done with its own initialization and thus the Guide gets a nullpointer because APP field is null.
The stacktrace is hidden so I can not tell what the problem is from your post, but as a tmp workaround, try
@F val guide = Guide(actionStream)
-> @F val guide by lazy { Guide(actionStream) }
if that does not work
The ultimate solution would use one of 2 approaches
An alternative solution is to initialize the static APP field right at the beginning - before any field from App initializes. I came up with this solution: ` // this is 1st field in the App.class private val initializationInvoker = singletonInitializate()
fun singletonInitializate() {
AppUtil.APP = this.takeIf { AppUtil.APP==null } ?: fail("Multiple application instances disallowed")
}
init {
/// this block no longer initializes the singleton APP field
}
`
Pls report if the last solution works and what you think about the proposed solutions.
Am I missing something? Idea shows me that there is no write access to AppUtil.APP
, which, to my understanding, means this variable will always be null
Okay I found it, but the error is super obvious. You are instantiating the Guide before setting the APP variable... I'll open a PR to discuss this.
The error is not obvious, because the problem appears inconsistently (only very rarely), which is nontrivial to explain.
It's not inconsistently, in the App Guide is instantiated before APP is set, so if the Guide tries to start it will always throw that error. But it only starts automatically at first startup, that's probably why you think it occurs very rarely.
You are right this is related to the guide starting when application is started for the 1st time, but not exclusively, I had the Guide NPE on me in other situations as well, probably some other module was invoking the guide.
I can't start the player right now from the main branch :/