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

NullPointerException potentially "safe area insets can be null" #3764

Closed
jnorth515 opened this issue Nov 15, 2023 · 6 comments
Closed

NullPointerException potentially "safe area insets can be null" #3764

jnorth515 opened this issue Nov 15, 2023 · 6 comments
Assignees

Comments

@jnorth515
Copy link

As requested I have filed an issue with ref to this question.

I have been receiving NullPointerException reports as per below. Often they occur just after the device orientation changes. example report below: -

[EDT] 11:19:53,486 - Orientation changed to Landscape - showHomeForm
[EDT] 11:19:53,490 - line 572
[EDT] 11:19:53,495 - line 574
[EDT] 11:19:53,935 - line 576
[EDT] 11:19:53,940 - Orientation changed to Landscape Finished - showHomeForm
[EDT] 11:19:53,954 - line 565
[EDT] 11:19:53,957 - Orientation changed to Portrait Finished - showHomeForm
[EDT] 11:19:58,803 - Exception: java.lang.NullPointerException - null
java.lang.NullPointerException at
com_codename1_impl_ios_IOSImplementation.getDisplaySafeArea:256
at com_codename1_ui_Container.snapToSafeAreaInternal:2395
at com_codename1_ui_Container.calcPreferredSize:3176
at com_codename1_ui_Component.preferredSizeImpl:3545
at com_codename1_ui_Component.preferredSize:3584
at com_codename1_ui_Component.getPreferredSize:1449
at com_codename1_ui_Component.getPreferredH:1539
at com_codename1_ui_layouts_BorderLayout.positionTopBottom:477
at com_codename1_ui_layouts_BorderLayout.layoutContainer:317
at com_codename1_ui_Container.doLayout:2583
at com_codename1_ui_Container.layoutContainer:2219
at com_codename1_ui_Container.doLayout:2588
at com_codename1_ui_Container.layoutContainer:2219
at com_codename1_ui_Container.doLayout:2588
at com_codename1_ui_Form.sizeChangedInternal:881
at com_codename1_ui_Display.handleEvent:2514
at com_codename1_ui_Display.edtLoopImpl:1300
at com_codename1_ui_Display.mainEDTLoop:1218
at com_codename1_ui_RunnableWrapper.run:120
at com_codename1_impl_CodenameOneThread.run:176
at java_lang_Thread.runImpl:153

[EDT] 11:19:58,823 - Exception in My App version 2.03
[EDT] 11:19:58,827 - OS ios
[EDT] 11:19:58,832 - Error java.lang.NullPointerException
[EDT] 11:19:58,836 - Current Form VXSMS_Main
[EDT] 11:19:58,840 - Exception: java.lang.NullPointerException - null
java.lang.NullPointerException at
com_codename1_impl_ios_IOSImplementation.getDisplaySafeArea:256
at com_codename1_ui_Container.snapToSafeAreaInternal:2395
at com_codename1_ui_Container.calcPreferredSize:3176
at com_codename1_ui_Component.preferredSizeImpl:3545
at com_codename1_ui_Component.preferredSize:3584
at com_codename1_ui_Component.getPreferredSize:1449
at com_codename1_ui_Component.getPreferredH:1539
at com_codename1_ui_layouts_BorderLayout.positionTopBottom:477
at com_codename1_ui_layouts_BorderLayout.layoutContainer:317
at com_codename1_ui_Container.doLayout:2583
at com_codename1_ui_Container.layoutContainer:2219
at com_codename1_ui_Container.doLayout:2588
at com_codename1_ui_Container.layoutContainer:2219
at com_codename1_ui_Container.doLayout:2588
at com_codename1_ui_Form.sizeChangedInternal:881
at com_codename1_ui_Display.handleEvent:2514
at com_codename1_ui_Display.edtLoopImpl:1300
at com_codename1_ui_Display.mainEDTLoop:1218
at com_codename1_ui_RunnableWrapper.run:120
at com_codename1_impl_CodenameOneThread.run:176
at java_lang_Thread.runImpl:153

Additional context
This only occurs with iOS and I have only been able to recreate this issue myself once. It was after a long period of inactivity. After this time, opening the app, the iPhone was displaying a message of low battery. I then rotated the device a few times.

@jnorth515
Copy link
Author

jnorth515 commented Nov 20, 2023

Hi did this fix make it to last Friday's update (7.0.128)? I have received another bug report the same as above: -

[EDT] 0:55:32,455 - Exception: java.lang.NullPointerException - null java.lang.NullPointerException
at com_codename1_impl_ios_IOSImplementation.getDisplaySafeArea:257
at com_codename1_ui_Container.snapToSafeAreaInternal:2395
at com_codename1_ui_Container.calcPreferredSize:3176
at com_codename1_ui_Component.preferredSizeImpl:3545
at com_codename1_ui_Component.preferredSize:3584
at com_codename1_ui_Component.getPreferredSize:1449
at com_codename1_ui_Component.getPreferredH:1539
at com_codename1_ui_layouts_BorderLayout.positionTopBottom:477
at com_codename1_ui_layouts_BorderLayout.layoutContainer:317
at com_codename1_ui_Container.doLayout:2583
at com_codename1_ui_Container.layoutContainer:2219
at com_codename1_ui_Container.doLayout:2588
at com_codename1_ui_Container.layoutContainer:2219
at com_codename1_ui_Container.revalidateInternal:1584
at com_codename1_ui_Container.revalidate:1554
at com_codename1_impl_ios_IOSImplementation_33.run:8573
at com_codename1_ui_Display.executeSerialCall:1410
at com_codename1_ui_Display.processSerialCalls:1394
at com_codename1_ui_Display.edtLoopImpl:1336
at com_codename1_ui_Display.mainEDTLoop:1218
at com_codename1_ui_RunnableWrapper.run:120
at com_codename1_impl_CodenameOneThread.run:176
at java_lang_Thread.runImpl:153
[EDT] 0:55:32,456 - Exception in My App version 2.03 [EDT] 0:55:32,457 - OS ios [EDT] 0:55:32,457 - Error java.lang.NullPointerException [EDT] 0:55:32,457 - Current Form VXSMS_Main [EDT] 0:55:32,457 - Exception: java.lang.NullPointerException - null java.lang.NullPointerException
at com_codename1_impl_ios_IOSImplementation.getDisplaySafeArea:257
at com_codename1_ui_Container.snapToSafeAreaInternal:2395
at com_codename1_ui_Container.calcPreferredSize:3176
at com_codename1_ui_Component.preferredSizeImpl:3545
at com_codename1_ui_Component.preferredSize:3584
at com_codename1_ui_Component.getPreferredSize:1449
at com_codename1_ui_Component.getPreferredH:1539
at com_codename1_ui_layouts_BorderLayout.positionTopBottom:477
at com_codename1_ui_layouts_BorderLayout.layoutContainer:317
at com_codename1_ui_Container.doLayout:2583
at com_codename1_ui_Container.layoutContainer:2219
at com_codename1_ui_Container.doLayout:2588
at com_codename1_ui_Container.layoutContainer:2219
at com_codename1_ui_Container.revalidateInternal:1584
at com_codename1_ui_Container.revalidate:1554
at com_codename1_impl_ios_IOSImplementation_33.run:8573
at com_codename1_ui_Display.executeSerialCall:1410
at com_codename1_ui_Display.processSerialCalls:1394
at com_codename1_ui_Display.edtLoopImpl:1336
at com_codename1_ui_Display.mainEDTLoop:1218
at com_codename1_ui_RunnableWrapper.run:120
at com_codename1_impl_CodenameOneThread.run:176
at java_lang_Thread.runImpl:153

@shai-almog
Copy link
Collaborator

Is this with the current build?

Assuming it is then it should be fixed and I'm reopening the issue.

@shai-almog shai-almog reopened this Nov 21, 2023
@jnorth515
Copy link
Author

Yes, I updated the project to version 7.0.128 and then released a new version. That report was from the latest version.

@jnorth515
Copy link
Author

As stated in the stackoverflow question: -
"This only occurs with iOS and I have only been able to recreate this issue myself once. It was after a long period of inactivity. After this time, opening the app, the iPhone was displaying a message of low battery. I then rotated the device a few times."

@jnorth515
Copy link
Author

Another today: -

[EDT] 0:0:15,839 - Exit smsapp - Display.SMS_INTERACTIVE [EDT] 0:0:15,839 - Exit b_gateTrigSMS Action
[EDT] 0:0:18,245 - Orientation changed to Landscape - showHomeForm
[EDT] 0:0:18,246 - line 582
[EDT] 0:0:18,247 - line 584
[EDT] 0:0:18,659 - line 586
[EDT] 0:0:18,660 - Orientation changed to Landscape Finished - showHomeForm
[EDT] 0:0:24,643 - Exception: java.lang.NullPointerException - null java.lang.NullPointerException
at com_codename1_impl_ios_IOSImplementation.getDisplaySafeArea:256
at com_codename1_ui_Container.snapToSafeAreaInternal:2395
at com_codename1_ui_Container.calcPreferredSize:3176
at com_codename1_ui_Component.preferredSizeImpl:3545
at com_codename1_ui_Component.preferredSize:3584
at com_codename1_ui_Component.getPreferredSize:1449
at com_codename1_ui_Component.getPreferredW:1529
at com_codename1_ui_layouts_BorderLayout.getPreferredSize:507
at com_codename1_ui_Container.calcPreferredSize:3180
at com_codename1_ui_Component.preferredSizeImpl:3545
at com_codename1_ui_Component.preferredSize:3584
at com_codename1_ui_Component.getPreferredSize:1449
at com_codename1_ui_Component.getPreferredH:1539
at com_codename1_ui_layouts_BorderLayout.positionTopBottom:477
at com_codename1_ui_layouts_BorderLayout.layoutContainer:317
at com_codename1_ui_Container.doLayout:2583
at com_codename1_ui_Form.sizeChangedInternal:881
at com_codename1_ui_Display.handleEvent:2514
at com_codename1_ui_Display.edtLoopImpl:1300
at com_codename1_ui_Display.mainEDTLoop:1218
at com_codename1_ui_RunnableWrapper.run:120
at com_codename1_impl_CodenameOneThread.run:176
at java_lang_Thread.runImpl:153
[EDT] 0:0:24,659 - Exception in My App version 2.03 [EDT] 0:0:24,659 - OS ios [EDT] 0:0:24,660 - Error java.lang.NullPointerException [EDT] 0:0:24,661 - Current Form VXSMS_Main [EDT] 0:0:24,662 - Exception: java.lang.NullPointerException - null java.lang.NullPointerException
at com_codename1_impl_ios_IOSImplementation.getDisplaySafeArea:256
at com_codename1_ui_Container.snapToSafeAreaInternal:2395
at com_codename1_ui_Container.calcPreferredSize:3176
at com_codename1_ui_Component.preferredSizeImpl:3545
at com_codename1_ui_Component.preferredSize:3584
at com_codename1_ui_Component.getPreferredSize:1449
at com_codename1_ui_Component.getPreferredW:1529
at com_codename1_ui_layouts_BorderLayout.getPreferredSize:507
at com_codename1_ui_Container.calcPreferredSize:3180
at com_codename1_ui_Component.preferredSizeImpl:3545
at com_codename1_ui_Component.preferredSize:3584
at com_codename1_ui_Component.getPreferredSize:1449
at com_codename1_ui_Component.getPreferredH:1539
at com_codename1_ui_layouts_BorderLayout.positionTopBottom:477
at com_codename1_ui_layouts_BorderLayout.layoutContainer:317
at com_codename1_ui_Container.doLayout:2583
at com_codename1_ui_Form.sizeChangedInternal:881
at com_codename1_ui_Display.handleEvent:2514
at com_codename1_ui_Display.edtLoopImpl:1300
at com_codename1_ui_Display.mainEDTLoop:1218
at com_codename1_ui_RunnableWrapper.run:120
at com_codename1_impl_CodenameOneThread.run:176
at java_lang_Thread.runImpl:153

@shai-almog
Copy link
Collaborator

shai-almog commented Nov 21, 2023

I posted another fix. There are two possibilities I can think of:

  • Race condition
  • Change in iOS 13

If this is only happening in iOS 13 or newer then the latter might be the reason in which case we will need to replace UIApplication.sharedApplication.keyWindow with UIApplication.sharedApplication.windows. E.g.:

        UIWindow *window = nil;
        if (@available(iOS 13.0, *)) {
            for (UIWindow *aWindow in UIApplication.sharedApplication.windows) {
                if (aWindow.isKeyWindow) {
                    window = aWindow;
                    break;
                }
            }
        } else {
            window = UIApplication.sharedApplication.keyWindow;
        }
        if (window != nil) {
            return (JAVA_INT)(window.safeAreaInsets.left * scaleValue);
        }

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

No branches or pull requests

3 participants