I have this code and I got this exception from Cra...
# android
h
I have this code and I got this exception from Crashlytics
Fatal Exception: java.lang.IllegalStateException: readValue(content, jacksonTypeRef<T>()) must not be null
I couldn’t understand what is being null here. Any idea?
r
This kind of message is ambiguous, but it actually says that a method
readValue(content, jacksonTypeRef<T>())
(probably called by your call to
mapper.readValue(string)
returns null while not allowed to. Or at least that's what I think is happening.
h
himm let me check the jackson implementation.
so the field is PasswordToken? so it is clearly nullable. the type reference obtained through reified type reference.
inline fun <reified T: Any> ObjectMapper.readValue(content: String): T = readValue(content, jacksonTypeRef<T>())
It should be return null. Anything I am missing here?
r
If
T: Any
, then
T
is not nullable,
T?
is. If
T: Any?
, then
T
is nullable.
For me something defined as
fun <T: Any> foo(): T
cannot return null
h
ok makes sense.
now I need to figure out how jackson can return null
I have run some tests the only way
mapper.readValue(string)
could return null is when string is null which doesn’t seem to be possible for me.
any ideas on this?
r
Did you read the actual implementation of the method?
h
yes
So I figured this finally. “null” string was returned from the SharedPreferences and jackson is returning null in this case.
Gael thank you for your help
r
👌