google-developer-training / basic-android-kotlin-compose-training-inventory-app

Apache License 2.0
77 stars 84 forks source link

Persist data with Room - wrong implementation of singleton initialization #122

Open Yonathan-Ashebir opened 3 months ago

Yonathan-Ashebir commented 3 months ago

URL of codelab

I have noticed what possibly could be an issue on STEP 7 of the code lab. image

At the end of this step (as shown in the screen shot), the code to create the database checks nullness of Instance in non-synchronized manner and it is after that it enters to the synchronized block to initialize it. Does not this create a race condition and allow re-initialization of the database? OR is this an acceptable behaviour when it comes to ROOM?