epoxy
epoxy copied to clipboard
NullPointerException when Epoxy model is bind to data class
I have noticed that epoxy throws this exception when the model use the data class with kotlin 1.5.10 and 1.5.0
java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.hashCode()' on a null object reference
at org.zxconnect.android.daylivro.models.entity.Product.hashCode(Unknown Source:19)
at org.zxconnect.android.delivro.ProductBindingModel_.hashCode(ProductBindingModel_.java:330)
sounds like a bug in your Product class's hashCode implementation calling hashCode on a null string
Yes, it is the exception that is triggered, but if I remove when I remove the keyword data, there is no more exception
In my model there is no property with null as default value, The application does not trigger the exception if I use Kotlin version 1.4.30
I had a non-nullable String variable in my data class but when my Api service started to send null variable to it, this error occurred.
Downgrade Kotlin version to 1.4.32 is also works but it's not a good option.
So i fixed this issue by converting some of my non-nullable variables to nullable variables like below.
Before:
data class ExampleClass {
val myNullableString: String
..
}
After:
data class ExampleClass {
val myNullableString: String?=null
..
}
Hello, got the same error. I had data class inside first data class, so when this is null, it throws NPE for hashCode(). Appeared after updating Kotlin version to 1.5.0

@zhambylgaziz i guess you must initialize your data class variable as nullable like me.
@tekinumut Thanks, i stuck with same issue, your reply solved that :)
I don't get why the compiler can't just tell you which field is causing the issue.