This repository was archived by the owner on Nov 1, 2022. It is now read-only.

Description
Related issue mozilla-mobile/fenix#4604.
We are seeing in some situations that siteTrackingProtection: SiteTrackingProtection is getting set to null even though it is a non-null value type and it's has a default value.
This is happening because override fun onCreateDrawableState in some situations is getting called from the super() constructor on the View class, way before the child class (TrackingProtectionIconView) get an opportunity to initialize its values (siteTrackingProtection) as a result we get a null pointer exception.
The below snipped can help to exemplify the issue:
class Parent{
Parent(){
overrideme();
}
public void overrideme() { }
}
class Child extends Parent{
String value ="value";
Child(){
System.out.println(value);
}
@Override
public void overrideme() {
System.out.println(value);
}
}
class HelloWorld{
public static void main(String[] args) {
Parent p = new Child();
}
}
Output:
-
The first print statement is null because we are trying to use the value property from the super() constructor before is initialized ( In every constructor, the first line to be called is super()).
-
Now we have the expected because after the super() constructor runs the properties in the child class get initialized.
More info related https://stackoverflow.com/questions/3404301/whats-wrong-with-overridable-method-calls-in-constructors and https://medium.com/keepsafe-engineering/an-in-depth-look-at-kotlins-initializers-a0420fcbf546
┆Issue is synchronized with this Jira Task