is this a compiler bug? ```open class Parent( ...
# k2-adopters
n
is this a compiler bug?
Copy code
open class Parent(
    open val numbers: List<Int>
) {
    val sortedNumbers: List<Int> = numbers.sorted()
}

class Child(
    override val numbers: List<Int>
): Parent(numbers)

fun main() {
    println(Child(emptyList()).sortedNumbers)
}
it fails with
Copy code
Exception in thread "main" java.lang.NullPointerException: Parameter specified as non-null is null: method kotlin.collections.CollectionsKt___CollectionsKt.sorted, parameter <this>
	at kotlin.collections.CollectionsKt___CollectionsKt.sorted(_Collections.kt)
	at Parent.<init>(Blah.kt:4)
	at Child.<init>(Blah.kt:9)
	at BlahKt.main(Blah.kt:12)
	at BlahKt.main(Blah.kt)
e
no, it's expected with how initialization works sad panda
this is equivalent to the Java
Copy code
public class Parent {
    private List<Int> numbers;
    private List<Int> sortedNumbers;
    public Parent(List<Int> numbers) {
        this.numbers = numbers;
        sortedNumbers = getNumbers().sorted();
    }
    public List<Int> getNumbers() {
        return numbers;
    }
    public final List<Int> getSortedNumbers() {
        return sortedNumbers;
    }
}

public final class Child extends Parent {
    private List<Int> numbers;
    public Child(List<Int> numbers) {
        super(numbers);
        this.numbers = numbers;
    }
    @Override
    public List<Int> getNumbers() {
        return numbers;
    }
}
notice that the constructor of
Parent
uses the overridable
getNumbers
, and at that point during construction, the backing field
Child.numbers
is still
null
open val
with a backing field is almost always a mistake
and using anything potentially overridable in a constructor is always a mistake