Skip to content

[pigeon] C++ generated code doesn't handle null arguments of custom class type #149174

Closed
flutter/packages
#6881

Description

@russellwheatley

Steps to reproduce

I have a reproduction repo here.

Code uses url launcher windows package. I essentially updated the messages/pigeon.dart and regenerated the code.

This is the update

In a nutshell, if an arg is nullable, and null is passed, it will crash the app. Here is where it crashes in the code. Essentially, when it tries to parse the nullable value.

I have instructions in the README of the reproduction repo, but here they are for completeness:

  1. Run flutter build windows --debug in example/
  2. Open app on Visual Studio by opening the solution in example/build/windows/x64/runner/runner.sln
  3. Put two break points on these lines. Note that it gets to the first line but will crash before getting to the second line.

This issue was found when implementing this feature on FlutterFire: https://github.com/firebase/flutterfire/pull/12825/files#diff-ad8aa9e593097c77254420c5c93cccbba4478ba947392296a18cceddc6068d85R4028-R4037

Expected results

Not to crash when passing null as nullable argument.

Actual results

Crashes in Pigeon generated code on this line

Code sample

Code sample

https://github.com/russellwheatley/pigeon_bug_windows/blob/master/README.md

Screenshots or Video

Screenshots / Video demonstration

image

Logs

Logs

None.

Flutter Doctor output

Doctor output
[√] Flutter (Channel stable, 3.19.6, on Microsoft Windows [Version 10.0.22631.3593], locale en-GB)
[√] Windows Version (Installed version of Windows is version 10 or higher)
[X] Android toolchain - develop for Android devices
    X Unable to locate Android SDK.
      Install Android Studio from: https://developer.android.com/studio/index.html
      On first launch it will assist you in installing the Android SDK components.
      (or visit https://flutter.dev/docs/get-started/install/windows#android-setup for detailed instructions).
      If the Android SDK has been installed to a custom location, please use
      `flutter config --android-sdk` to update to that location.

[√] Chrome - develop for the web
[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.8.3)
[!] Android Studio (not installed)
[√] VS Code (version 1.89.1)
[√] Connected device (3 available)
[√] Network resources

Activity

  1. changed the title [-]Pigeon plugin bug for nullable args in generated C++ API[/-] [+]Pigeon package bug for nullable args in generated C++ API[/+] on May 28, 2024
  2. added
    c: crashStack traces logged to the console
    platform-windowsBuilding on or for Windows specifically
    packageflutter/packages repository. See also p: labels.
    p: pigeonrelated to pigeon messaging codegen tool
    on May 28, 2024
  3. stuartmorgan-g commented on May 28, 2024

    @stuartmorgan-g
    Contributor

    I thought we had tests covering every arg type both nullable and non-nullable, but it looks like we missed null custom class top-level arguments somehow.

    I'll see if the custom codec PR fixes this; if so we can just track adding an integration test for this here.

  4. changed the title [-]Pigeon package bug for nullable args in generated C++ API[/-] [+][pigeon] C++ generated code doesn't handle null arguments of custom class type[/+] on May 28, 2024
  5. stuartmorgan-g commented on May 28, 2024

    @stuartmorgan-g
    Contributor

    I'll see if the custom codec PR fixes this

    It doesn't. I'll look at fixing this once the custom codec changes land.

    In the short term, a workaround would be to wrap the nullable class in a non-nullable class whose only field is the nullable class.

  6. added
    P1High-priority issues at the top of the work list
    on May 28, 2024
  7. stuartmorgan-g commented on May 28, 2024

    @stuartmorgan-g
    Contributor

    I have a trivial fix, which I can land once custom codecs land.

  8. russellwheatley commented on May 29, 2024

    @russellwheatley
    Author

    Thank you for the quick turn around, @stuartmorgan. I look forward to its release 🙏

  9. github-actions commented on Jun 21, 2024

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  10. locked as resolved and limited conversation to collaborators on Jun 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

P1High-priority issues at the top of the work listc: crashStack traces logged to the consolep: pigeonrelated to pigeon messaging codegen toolpackageflutter/packages repository. See also p: labels.platform-windowsBuilding on or for Windows specificallyteam-ecosystemOwned by Ecosystem team

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions