From 07ab938719576fe48a83eb9c5614bf0ea77c78cb Mon Sep 17 00:00:00 2001 From: Mygod Date: Wed, 17 Aug 2016 12:52:21 +0800 Subject: [PATCH] Prevent createProfile returns null --- .../com/github/shadowsocks/database/ProfileManager.scala | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/scala/com/github/shadowsocks/database/ProfileManager.scala b/src/main/scala/com/github/shadowsocks/database/ProfileManager.scala index 6ddded9c..7af7a4e2 100644 --- a/src/main/scala/com/github/shadowsocks/database/ProfileManager.scala +++ b/src/main/scala/com/github/shadowsocks/database/ProfileManager.scala @@ -53,9 +53,9 @@ class ProfileManager(dbHelper: DBHelper) { def setProfileAddedListener(listener: Profile => Any) = this.profileAddedListener = listener def createProfile(p: Profile = null): Profile = { + val profile = if (p == null) new Profile else p + profile.id = 0 try { - val profile = if (p == null) new Profile else p - profile.id = 0 app.currentProfile match { case Some(oldProfile) => // Copy Feature Settings from old profile @@ -72,13 +72,12 @@ class ProfileManager(dbHelper: DBHelper) { if (last != null && last.length == 1 && last(0) != null) profile.userOrder = last(0).toInt + 1 dbHelper.profileDao.createOrUpdate(profile) if (profileAddedListener != null) profileAddedListener(profile) - profile } catch { case ex: Exception => Log.e(TAG, "addProfile", ex) app.track(ex) - p } + profile } def updateProfile(profile: Profile): Boolean = {