Hey all. I’m wondering how this exception `java.la...
# announcements
o
Hey all. I’m wondering how this exception
java.lang.NullPointerException: Attempt to invoke virtual method 'float java.lang.Number.floatValue()' on a null object reference
can occur while iterating over a
MutableList<Float
. All
Float
values that are added to the list are
nonNull
; a
Float
value is returned from one function (where the return type is
Float
), used by a different function (where the parameter type is
Float
), and then added to the
MutableList<Float>
. Later I iterate over the list (
for (i in 0 until list.size) list[i]
) and it is here when the exception is thrown, when I’m getting the values from the list. I’ve only ever seen this happen once from crashlytics, but I cannot understand how it even happened once. Values are only added to the list at one point in my execution. After adding values to the list, and before iterating over the list, I may remove the last value in the list (
list.removeAt(list.size - 1)
). Looking at the decompiled code (
((Number)this.list.get(index)).floatValue()
) tells me that the value at that index is null. Am I misunderstanding the stack trace? Could someone please clear this up for me?
z
What kind of device? I’ve seen crash reports from some smaller manufacturers that seem to indicate they’re performing basic math incorrectly.
j
In order of likelihood: 1. You added a null to the list 2. Off by one error when populating the list - do you have a null check when adding? 3. Multi-threading (you didn't lock during population or removal or retrieval) 4. Value was later overwritten by program 5. Memory corruption - exceedingly unlikely The key is that Floats are immutable and walking past the end of the list results in an IndexOutOfBoundsException which you are not seeing. So the list does contain a null.
e
maybe modified outside of kotlin world?