class Foo(val b: Bar)
@JvmInline
value class Bar(val x: Int) {
init {
require(x > 0)
}
}
Since Bar is an inline value class, it is represented as an unboxed integer. When Dalesbred instantiates Foo it doesn't consult Kotlin's metadata and will pass the integer it receives from database directly to the Foo's constructor. If there is a non-positive number in the database, the require-call will not be made and exception will not be thrown.
Kotlin does generate a static constructor-impl -method for Bar that we could call to make sure that init-block will be called, but first we'd need to parse Kotlin metadata to detect the situation.
Consider the following:
Since Bar is an inline value class, it is represented as an unboxed integer. When Dalesbred instantiates Foo it doesn't consult Kotlin's metadata and will pass the integer it receives from database directly to the Foo's constructor. If there is a non-positive number in the database, the require-call will not be made and exception will not be thrown.
Kotlin does generate a static
constructor-impl
-method for Bar that we could call to make sure that init-block will be called, but first we'd need to parse Kotlin metadata to detect the situation.