Secured-Preference-Store icon indicating copy to clipboard operation
Secured-Preference-Store copied to clipboard

Failed to init Secured Preference Store. Exception: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String

Open minadaki opened this issue 6 years ago • 4 comments

Hello,

I am using the latest version of the library (0.7.2). I noticed that the init function was marked as deprecated so I tried to use the new init function (by the way, the description of the new function is missing the @param annotations for the newly added input fields).

The extra arguments of the new init function: private static final String SECURE_PREFS_NAME = "secPrefs";
private static final String SECURE_KEY_PREFIX = "testvss"; private static final byte[] SECURE_PREFS_SEED = "seed".getBytes();

The stack trace of the error: W/System.err: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String at devliving.online.securedpreferencestore.SecuredPreferenceStore$MigrationHelper.migrateToV10(SecuredPreferenceStore.java:491) at devliving.online.securedpreferencestore.SecuredPreferenceStore$MigrationHelper.migrate(SecuredPreferenceStore.java:548) at devliving.online.securedpreferencestore.SecuredPreferenceStore$MigrationHelper.migrate(SecuredPreferenceStore.java:537) at devliving.online.securedpreferencestore.SecuredPreferenceStore.(SecuredPreferenceStore.java:60) at devliving.online.securedpreferencestore.SecuredPreferenceStore.init(SecuredPreferenceStore.java:116) at initializeSecurePreferences(Application.java:136).

Can you please check? Also, how can I enable the library specific logs?

minadaki avatar Jul 09 '18 10:07 minadaki

couldn't reproduce this issue but 57f976c safeguards the code that might have caused this issue. @minadaki can you please try the latest code and see if it fixes the issue?

iamMehedi avatar Jul 09 '18 15:07 iamMehedi

Hello, Thank you for your fast reply. Unfortunately, even with the latest version, the app still crashes.

The library fails to initialise:

Failed to init Secured Preference Store. Exception: java.lang.ArrayIndexOutOfBoundsException: length=1; index=1 at devliving.online.securedpreferencestore.SecuredPreferenceStore.<init>(SecuredPreferenceStore.java:76) at devliving.online.securedpreferencestore.SecuredPreferenceStore.init(SecuredPreferenceStore.java:134)

The actual crash takes place later when the app tries to use Secured Shared Preferences:

07-10 10:28:21.040 32191-32191/x.x.x E/AndroidRuntime: FATAL EXCEPTION: main Process: /x.x.x, PID: 32191 java.lang.RuntimeException: Unable to start activity ComponentInfo{/x.x.x/x.x.x.LoginActivity}: java.lang.IllegalStateException: Must call init() before using the store at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2955) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3030) at android.app.ActivityThread.-wrap11(Unknown Source:0) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696) at android.os.Handler.dispatchMessage(Handler.java:105) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6938) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374) Caused by: java.lang.IllegalStateException: Must call init() before using the store at devliving.online.securedpreferencestore.SecuredPreferenceStore.getSharedInstance(SecuredPreferenceStore.java:99)

This is how I initialise the library: private static final String SECURE_PREFS_NAME = "secPrefs"; private static final String SECURE_KEY_PREFIX = "testvss"; private static final byte[] SECURE_PREFS_SEED = "seed".getBytes(); SecuredPreferenceStore.init(getApplicationContext(), SECURE_PREFS_NAME, SECURE_KEY_PREFIX, SECURE_PREFS_SEED, new DefaultRecoveryHandler2());

Testing device: Samsung S8, Android Oreo (8.0.0)

minadaki avatar Jul 10 '18 07:07 minadaki

Haven't been able to reproduce this so far. Have you tested on any other device except the Samsung? @minadaki

iamMehedi avatar Jul 12 '18 05:07 iamMehedi

I tried on a Motorolla phone running Android Oreo and it worked fine. After that I uninstalled my app from the Samsung S8 phone and cleared all the app's cache and data. Upon re-installing the app, the library initialised successfully and no crashes occurred. So where does that leave us? If I upload a new version of my app in Playstore including the changes, will the app crash after updating or not? Does update of the app clear cache and data (simulating the uninstall-install scenario) ?

minadaki avatar Jul 12 '18 10:07 minadaki