title: Android Keystore.getEntry NullPointerException
body: <p>My App crashes several times for several users.
  But I can't repeat that situation, I can only find them in Google Play Console.</p>
  <p>some people told me alias could be problem, because keyStore.getEntry returns NPE when alias is null,</p>
  <p>but I put string value to alias. so it could not be null.
  Please help me...</p>
  <p>This is Crash Information</p>
  <pre><code>java.lang.RuntimeException: 
  at android.app.ActivityThread.handleMakeApplication (ActivityThread.java:7189)
  at android.app.ActivityThread.handleBindApplication (ActivityThread.java:7134)
  at android.app.ActivityThread.access$1600 (ActivityThread.java:274)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:2102)
  at android.os.Handler.dispatchMessage (Handler.java:107)
  at android.os.Looper.loop (Looper.java:237)
  at android.app.ActivityThread.main (ActivityThread.java:8167)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:496)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1100)
  Caused by: java.lang.NullPointerException: 
  at java.security.KeyStore$PrivateKeyEntry.&lt;init&gt; (KeyStore.java:559)
  at java.security.KeyStore$PrivateKeyEntry.&lt;init&gt; (KeyStore.java:526)
  at java.security.KeyStoreSpi.engineGetEntry (KeyStoreSpi.java:527)
  at java.security.KeyStore.getEntry (KeyStore.java:1623)
  at com.hpml_19102301.util.AndroidKeyStoreUtil.init$app_release (AndroidKeyStoreUtil.kt:76)
  at com.hpml_19102301.application.HappApplication.onCreate (HappApplication.kt:25)
  at android.app.Instrumentation.callApplicationOnCreate (Instrumentation.java:1190)
  at android.app.ActivityThread.handleMakeApplication (ActivityThread.java:7184)
  </code></pre>
  <p>This is my code.</p>
  <pre><code>private lateinit var keyEntry: KeyStore.Entry
  
  @Suppress(&quot;ObjectPropertyName&quot;)
  private var _isSupported = false
  
  private val isSupported: Boolean
      get() = _isSupported
  
  private lateinit var appContext: Context
  
  internal fun init(applicationContext: Context) {
      if (isSupported) {
          Log.e(&quot;temp&quot;, &quot;Already init twice!&quot;)
          return
      }
  
      this.appContext = applicationContext
      val alias = &quot;${appContext.packageName}.rsakeypairs&quot;
      val keyStore = KeyStore.getInstance(KEYSOTRE_INSTANCE_TYPE).apply {
          load(null)
      }
  
      var result: Boolean = if (keyStore.containsAlias(alias)) {
          true
      } else {
          // use RSA 
          if (initAndroidM(alias)) {
              true
          } else {
              initAndroidL(alias)
          }
      }
  
      //Specific line which throws NPE!
      this.keyEntry = keyStore.getEntry(alias, null)  //TODO: The code when throws NPE 
      _isSupported = result
  }
  </code></pre>