Dependency is null when trying to access it on abstract class property initialisation
Filling this as a bug but don't know if it is a bug.
My ProductsViewModel implements the abstract class AbstractProductsViewModel.
I'm passing some dependencies to the ProductsViewModel and when the AbstractProductsViewModel is being created, one of its properties triggers a method in ProductsViewModel.
open val product: LiveData<Product> = {
// gets the product from the database and calls method in ProductsViewModel
generateProduct(product)
}
I'm getting the error:
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'androidx.lifecycle.LiveData com.XXX.repository.ProductsRepository.getProductNumber()' on a null object reference
at com.XXX.ProductsViewModel.generateProduct(ProductsViewModel.kt:82)
at com.XXX.AbstractProductsViewModel.<init>(AbstractProductsViewModel.kt:54)
at com.XXX.ProductsViewModel.<init>(ProductsViewModel.kt:35)
ProductsRepository is being passed in the constructor and while I'm debugging I can see that it is not null but when I try to access it is null.
I put a breakpoint just before trying to access the ProductsRepository in the generateProduct product method and in there, it is null but if I go up in the debugger "frames" I can see it is not null.

Any idea why and How can I overcome this?
Have you found any solution for this issue?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
I did face the very same issue