Skip to content

Commit

Permalink
Perform null check inside the synchronized block
Browse files Browse the repository at this point in the history
  • Loading branch information
darshanparajuli committed Aug 19, 2018
1 parent 8530593 commit 4a99b9e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions app/src/main/java/com/dp/logcatapp/db/MyDB.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,16 @@ abstract class MyDB : RoomDatabase() {
private var instance: MyDB? = null

fun getInstance(context: Context): MyDB {
if (instance == null) {
synchronized(MyDB::class) {
synchronized(MyDB::class) {
if (instance == null) {
instance = Room.databaseBuilder(context.applicationContext,
MyDB::class.java, DB_NAME)
.addMigrations(MIGRATION_1_2)
.fallbackToDestructiveMigration()
.build()
}
return instance!!
}
return instance!!
}

private val MIGRATION_1_2 = object : Migration(1, 2) {
Expand Down

0 comments on commit 4a99b9e

Please sign in to comment.