Decoding into Kotlin data class fails with NullPointerException: Cannot invoke java.lang.Number.intValue()

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Unresolved
    • Priority: Unknown
    • None
    • Affects Version/s: None
    • Component/s: Kotlin
    • None
    • None
    • Java Drivers
    • None
    • None
    • None
    • None
    • None
    • None

      Summary

      I'm trying to serialize the data class:

      @Serializable
      data class User(
      val name: String = "MISSING",
      val isAlive: Boolean = true,
      val age: Int,
      )
      

      This fails with:

      java.lang.IllegalArgumentException: java.lang.NullPointerException: Cannot invoke "java.lang.Number.intValue()" because the return value of "sun.invoke.util.ValueConversions.primitiveConversion(sun.invoke.util.Wrapper, Object, boolean)" is null
          at java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:70)
          at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:502)
          at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:486)
          at kotlin.reflect.jvm.internal.calls.CallerImpl$Constructor.call(CallerImpl.kt:41)
          at kotlin.reflect.jvm.internal.KCallableImpl.callDefaultMethod$kotlin_reflection(KCallableImpl.kt:207)
          at kotlin.reflect.jvm.internal.KCallableImpl.callBy(KCallableImpl.kt:112)
          at org.bson.codecs.kotlin.DataClassCodec.decode(DataClassCodec.kt:104)
          ... 63 more_
      Caused by: java.lang.NullPointerException: Cannot invoke "java.lang.Number.intValue()" because the return value of "sun.invoke.util.ValueConversions.primitiveConversion(sun.invoke.util.Wrapper, Object, boolean)" is null
          at java.base/sun.invoke.util.ValueConversions.unboxInteger(ValueConversions.java:81)
          at java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:62)
          ... 69 more
      

      Motivation

      Who is the affected end user?

      Who are the stakeholders?

      How does this affect the end user?

      Are they blocked? Are they annoyed? Are they confused?

      How likely is it that this problem or use case will occur?

      Main path? Edge case?

      If the problem does occur, what are the consequences and how severe are they?

      Minor annoyance at a log message? Performance concern? Outage/unavailability? Failover can't complete?

      Is this issue urgent?

            Assignee:
            Ross Lawley
            Reporter:
            Ivan Canet
            None
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: