Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix snackbar NPE #4396

Merged
merged 1 commit into from
Nov 22, 2021
Merged

Fix snackbar NPE #4396

merged 1 commit into from
Nov 22, 2021

Conversation

skyler-stripe
Copy link
Contributor

Summary

We were trying to initialize our snackbar in the example apps too soon. If we switch to lazy initialization, the snackbar is in a good state by the time we need it.

Motivation

2021-11-22 08:44:49.778 7861-7861/com.stripe.android.paymentsheet.example E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.stripe.android.paymentsheet.example, PID: 7861
    java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.stripe.android.paymentsheet.example/com.stripe.android.paymentsheet.example.samples.activity.LaunchPaymentSheetCompleteActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.pm.ApplicationInfo android.content.Context.getApplicationInfo()' on a null object reference
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3365)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:223)
        at android.app.ActivityThread.main(ActivityThread.java:7656)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
     Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.pm.ApplicationInfo android.content.Context.getApplicationInfo()' on a null object reference
        at android.content.ContextWrapper.getApplicationInfo(ContextWrapper.java:173)
        at android.view.ContextThemeWrapper.getTheme(ContextThemeWrapper.java:174)
        at android.content.Context.obtainStyledAttributes(Context.java:744)
        at androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor(AppCompatDelegateImpl.java:842)
        at androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor(AppCompatDelegateImpl.java:809)
        at androidx.appcompat.app.AppCompatDelegateImpl.findViewById(AppCompatDelegateImpl.java:633)
        at androidx.appcompat.app.AppCompatActivity.findViewById(AppCompatActivity.java:259)
        at com.stripe.android.paymentsheet.example.samples.activity.BasePaymentSheetActivity.<init>(BasePaymentSheetActivity.kt:48)
        at com.stripe.android.paymentsheet.example.samples.activity.LaunchPaymentSheetCompleteActivity.<init>(LaunchPaymentSheetCompleteActivity.kt:10)
        at java.lang.Class.newInstance(Native Method)
        at android.app.AppComponentFactory.instantiateActivity(AppComponentFactory.java:95)
        at androidx.core.app.CoreComponentFactory.instantiateActivity(CoreComponentFactory.java:45)
        at android.app.Instrumentation.newActivity(Instrumentation.java:1253)

#4390

Testing

  • Added tests
  • Modified tests
  • Manually verified

@github-actions
Copy link
Contributor

Diffuse output:

OLD: paymentsheet-example-release-master.apk (signature: none)
NEW: paymentsheet-example-release-pr.apk (signature: none)

          │          compressed          │          uncompressed          
          ├──────────┬──────────┬────────┼───────────┬───────────┬────────
 APK      │ old      │ new      │ diff   │ old       │ new       │ diff   
──────────┼──────────┼──────────┼────────┼───────────┼───────────┼────────
      dex │ 11.7 MiB │ 11.7 MiB │ -315 B │  39.9 MiB │  39.9 MiB │ +396 B 
     arsc │  1.4 MiB │  1.4 MiB │    0 B │   1.4 MiB │   1.4 MiB │    0 B 
 manifest │  2.6 KiB │  2.6 KiB │    0 B │  10.6 KiB │  10.6 KiB │    0 B 
      res │  651 KiB │  651 KiB │    0 B │     1 MiB │     1 MiB │    0 B 
    asset │ 77.8 KiB │ 77.8 KiB │   +7 B │ 109.3 KiB │ 109.3 KiB │   +7 B 
    other │   78 KiB │   78 KiB │    0 B │   154 KiB │   154 KiB │    0 B 
──────────┼──────────┼──────────┼────────┼───────────┼───────────┼────────
    total │ 13.9 MiB │ 13.9 MiB │ -308 B │  42.5 MiB │  42.5 MiB │ +403 B 


         │          raw           │            unique            
         ├────────┬────────┬──────┼────────┬────────┬────────────
 DEX     │ old    │ new    │ diff │ old    │ new    │ diff       
─────────┼────────┼────────┼──────┼────────┼────────┼────────────
   files │      3 │      3 │    0 │        │        │            
 strings │ 182295 │ 182296 │   +1 │ 168444 │ 168445 │ +1 (+7 -6) 
   types │  32275 │  32276 │   +1 │  30555 │  30556 │ +1 (+1 -0) 
 classes │  28229 │  28230 │   +1 │  28229 │  28230 │ +1 (+1 -0) 
 methods │ 163653 │ 163656 │   +3 │ 159134 │ 159137 │ +3 (+3 -0) 
  fields │ 110192 │ 110193 │   +1 │ 109850 │ 109851 │ +1 (+2 -1) 


 ARSC    │ old  │ new  │ diff 
─────────┼──────┼──────┼──────
 configs │  287 │  287 │  0   
 entries │ 4362 │ 4362 │  0
APK
    compressed    │   uncompressed   │                               
─────────┬────────┼─────────┬────────┤                               
 size    │ diff   │ size    │ diff   │ path                          
─────────┼────────┼─────────┼────────┼───────────────────────────────
 3.4 MiB │ -315 B │ 9.9 MiB │ +396 B │ ∆ classes2.dex                
 5.6 KiB │   +7 B │ 5.4 KiB │   +7 B │ ∆ assets/dexopt/baseline.prof 
─────────┼────────┼─────────┼────────┼───────────────────────────────
 3.4 MiB │ -308 B │ 9.9 MiB │ +403 B │ (total)
DEX
STRINGS:

   old    │ new    │ diff       
  ────────┼────────┼────────────
   168444 │ 168445 │ +1 (+7 -6) 
  
  + :
  ���
  ���
  ���
  ���
  ���
  ���
  ���
  ���
  
  ���
  ���
  ���
  ���
  ���
  ���� � �2�0�:��B�¢����J�����0�2�����0�H�J_����0�2�����������0�����0�����0�0�H�R�����0�8DX���¢�
  �����������R��	��0
  8DX���¢�
  ��
  �������¨��
  + Lcom/stripe/android/paymentsheet/example/samples/activity/BasePaymentSheetActivity_snackbar_2;
  + SMAP
  BasePaymentSheetActivity.kt
  Kotlin
  *S Kotlin
  *F
  + 1 BasePaymentSheetActivity.kt
  com/stripe/android/paymentsheet/example/samples/activity/BasePaymentSheetActivityKt
  + 2 Row.kt
  androidx/compose/foundation/layout/RowKt
  + 3 Layout.kt
  androidx/compose/ui/layout/LayoutKt
  + 4 CompositionLocal.kt
  androidx/compose/runtime/CompositionLocal
  + 5 Composables.kt
  androidx/compose/runtime/ComposablesKt
  + 6 Dp.kt
  androidx/compose/ui/unit/DpKt
  + 7 Column.kt
  androidx/compose/foundation/layout/ColumnKt
  *L
  1#1,282:1
  69#2,6:283
  75#2:313
  79#2:355
  69#2,6:356
  75#2:386
  79#2:391
  68#2,7:392
  75#2:423
  70#2,5:424
  75#2:453
  79#2:459
  79#2:464
  72#3:289
  73#3,9:291
  72#3:321
  73#3,9:323
  84#3:349
  84#3:354
  72#3:362
  73#3,9:364
  84#3:390
  72#3:399
  73#3,9:401
  72#3:429
  73#3,9:431
  84#3:458
  84#3:463
  76#4:290
  76#4:322
  76#4:363
  76#4:400
  76#4:430
  418#5,13:300
  418#5,13:332
  431#5,3:346
  431#5,3:351
  418#5,13:373
  431#5,3:387
  418#5,13:410
  418#5,13:440
  431#5,3:455
  431#5,3:460
  155#6:314
  155#6:454
  155#6:465
  155#6:466
  155#6:467
  68#7,6:315
  74#7:345
  78#7:350
  *S KotlinDebug
  *F
  + 1 BasePaymentSheetActivity.kt
  com/stripe/android/paymentsheet/example/samples/activity/BasePaymentSheetActivityKt
  *L
  148#1:283,6
  148#1:313
  148#1:355
  184#1:356,6
  184#1:386
  184#1:391
  212#1:392,7
  212#1:423
  221#1:424,5
  221#1:453
  221#1:459
  212#1:464
  148#1:289
  148#1:291,9
  157#1:321
  157#1:323,9
  157#1:349
  148#1:354
  184#1:362
  184#1:364,9
  184#1:390
  212#1:399
  212#1:401,9
  221#1:429
  221#1:431,9
  221#1:458
  212#1:463
  148#1:290
  157#1:322
  184#1:363
  212#1:400
  221#1:430
  148#1:300,13
  157#1:332,13
  157#1:346,3
  148#1:351,3
  184#1:373,13
  184#1:387,3
  212#1:410,13
  221#1:440,13
  221#1:455,3
  212#1:460,3
  154#1:314
  233#1:454
  257#1:465
  278#1:466
  91#1:467
  157#1:315,6
  157#1:345
  157#1:350
  *E
  
  + SMAP
  BasePaymentSheetActivity.kt
  Kotlin
  *S Kotlin
  *F
  + 1 BasePaymentSheetActivity.kt
  com/stripe/android/paymentsheet/example/samples/activity/BasePaymentSheetActivityKt_Receipt_1
  + 2 Dp.kt
  androidx/compose/ui/unit/DpKt
  + 3 Column.kt
  androidx/compose/foundation/layout/ColumnKt
  + 4 Layout.kt
  androidx/compose/ui/layout/LayoutKt
  + 5 CompositionLocal.kt
  androidx/compose/runtime/CompositionLocal
  + 6 Composables.kt
  androidx/compose/runtime/ComposablesKt
  *L
  1#1,282:1
  155#2:283
  155#2:284
  155#2:316
  155#2:317
  155#2:318
  68#3,6:285
  74#3:315
  68#3,6:319
  74#3:349
  78#3:354
  78#3:359
  72#4:291
  73#4,9:293
  72#4:325
  73#4,9:327
  84#4:353
  84#4:358
  76#5:292
  76#5:326
  418#6,13:302
  418#6,13:336
  431#6,3:350
  431#6,3:355
  *S KotlinDebug
  *F
  + 1 BasePaymentSheetActivity.kt
  com/stripe/android/paymentsheet/example/samples/activity/BasePaymentSheetActivityKt_Receipt_1
  *L
  107#1:283
  108#1:284
  111#1:316
  113#1:317
  119#1:318
  105#1:285,6
  105#1:315
  129#1:319,6
  129#1:349
  129#1:354
  105#1:359
  105#1:291
  105#1:293,9
  129#1:325
  129#1:327,9
  129#1:353
  105#1:358
  105#1:292
  129#1:326
  105#1:302,13
  129#1:336,13
  129#1:350,3
  105#1:355,3
  *E
  
  + SMAP
  BasePaymentSheetActivity.kt
  Kotlin
  *S Kotlin
  *F
  + 1 BasePaymentSheetActivity.kt
  com/stripe/android/paymentsheet/example/samples/activity/ComposableSingletons_BasePaymentSheetActivityKt_lambda-1_1
  + 2 Column.kt
  androidx/compose/foundation/layout/ColumnKt
  + 3 Layout.kt
  androidx/compose/ui/layout/LayoutKt
  + 4 CompositionLocal.kt
  androidx/compose/runtime/CompositionLocal
  + 5 Composables.kt
  androidx/compose/runtime/ComposablesKt
  *L
  1#1,282:1
  68#2,6:283
  74#2:313
  78#2:318
  72#3:289
  73#3,9:291
  84#3:317
  76#4:290
  418#5,13:300
  431#5,3:314
  *S KotlinDebug
  *F
  + 1 BasePaymentSheetActivity.kt
  com/stripe/android/paymentsheet/example/samples/activity/ComposableSingletons_BasePaymentSheetActivityKt_lambda-1_1
  *L
  122#1:283,6
  122#1:313
  122#1:318
  122#1:289
  122#1:291,9
  122#1:317

...✂

@skyler-stripe skyler-stripe merged commit b248269 into master Nov 22, 2021
@skyler-stripe skyler-stripe deleted the snackbarNPE branch November 22, 2021 18:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants