How do I read an exception like this? Line 69 does...
# getting-started
j
How do I read an exception like this? Line 69 doesn't exists and line 10 is just the constructor
Copy code
java.lang.NullPointerException: null cannot be cast to non-null type kotlin.Number
	at com.apurebase.puredynamic.repository.user.mapping.UserMapping.<init>(UserMapping.kt:69) ~[main/:?]
	at com.apurebase.puredynamic.repository.user.mapping.UserMapping.<init>(UserMapping.kt:10) ~[main/:?]
j
Could you please share the corresponding code?
<init>
is indeed referring to the constructor of
UserMapping
. Are there any more lines in the stacktace? Are you running a regular Kotlin program or a Kotlin Script?
j
I'm running a huge jvm kotlin webservice.
Copy code
class UserMapping(di: DI, tableSchema: String? = null) : ModelMapping<User>(
    name = "USERS",
    config = di.direct.instance(),
    tableSchema = tableSchema
), ApbVersionedWithTimestamp {
I just restructured my models (about 1000 dataclasses) to use
Number
instead of
Int
. And now I get this runtime error, but it doesn't point out what or where that is causing it to fail 😕
j
I just restructured my models (about 1000 dataclasses) to use Number instead of Int
Wow, now I am quite curious as to why 😄
j
For IDs, just thought to use
Number
instead of
Long
😛 But seems like I put myself in a bad situation.
j
I'm suspecting the line number 69 may correspond to the generated overload of the constructor that accomodates default values. But is the stacktrace that small? Maybe it would be interesting to know what called your constructor, and whether there is a number involved somewhere, because it seems quite confusing here
Also, this is a dumb question but are you sure you're looking at the source of the code that throws this exception? It happened to me countless times that I was looking at a later revision of the code (master branch vs production), or just looking at another branch, or even just automatically cleaning unused imports that would shift the rest of the code
a
If you are using Intellij, use the “Analyze Stack Trace” option. That may help. Just paste it in there, as it will help deal with inlined code and whatnot that is not in source.
👌 1
😍 1
c
Those big Java frameworks may be doing some bytecode manipulation, which might be part of the issue. Also, it might not know exactly how to convert a value to
Number
, since it doesn’t really have a physical meaning (it’s an abstract class and doesn’t correspond to any particular primitive type, unlike int, double, etc.). In this case, I’d suspect the framework to pass
null
when it cannot perform the value mapping, which can cause these kinds of strange NPEs that shouldn’t be able to happen in pure Kotlin code Maybe consider converting everything to
Double
instead of
Number
?
j
it's a Kotlin ORM framework on top of jdbc. I've attached the full stacktrace. The analyzer didn't help much, but I did find the issue, it's inside the framework as Casey noted. Was just a bit hard to find the issue, as it's not even close to where the stacktrace is pointing to.