Delegated fields throw NPE


Hello I want to report a bug. I have an hibernate entity that is returning NPE for the delegated fields.

---- BaseUser.kt ----

  @Inheritance(strategy = JOINED)
  abstract class BaseUser(
    id: Long,

    @JoinColumn(name = "base_user_id", referencedColumnName = "id", nullable = false, unique = true)
    private val user User
) BaseModel(id) { val email: String by user }

---- User.kt ----

  data class User(
      @Id val id: Long,
      var email: String
  ) {
      operator fun <T> getValue(user: User, property: KProperty<*>) : T {
          return User::class.declaredMemberProperties.first { == }.get(this) as T

When I get this entity from the DB the email is null and the email$delegate throws NPE. Checking the decompiled java code I see that it has a non-args constructor which is not setting the delegate behaviour.

---- ----

  public BaseUser(long id, @NotNull User user) {
    Intrinsics.checkParameterIsNotNull(user, "user");
    this.user = user;$delegate = this.user;

  public BaseUser() {


Hello. Thank you for the report. Unfortunately I couldn’t build a reproducible test case from the code that you provided. Could you please create an issue at with a sample project that reproduces the bug? Thanks!