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

Pigeon: using Map or dynamic throws Generic type arguments must be nullable in field "data" error #94689

Closed
ben-xD opened this issue Dec 5, 2021 · 8 comments
Labels
found in release: 2.5 Found to occur in 2.5 found in release: 2.6 Found to occur in 2.6 has reproducible steps The issue has been confirmed reproducible and is ready to work on p: pigeon related to pigeon messaging codegen tool package flutter/packages repository. See also p: labels. r: invalid Issue is closed as not valid

Comments

@ben-xD
Copy link

ben-xD commented Dec 5, 2021

As per the Pigeon docs, I am tagging @gaaclarke to get help on this. Thanks in advance.

Attempt 1

I've tried to define a class using:

class RemoteMessage {
  Notification? notification;
  Map<String, dynamic>? data;
}

Unfortunately, I get an error message:

Error: pigeons/push.dart:6: Generic type arguments must be nullable in field "data" in class "RemoteMessage".
Error: pigeons/push.dart:6: Generic type arguments must be nullable in field "data" in class "RemoteMessage".

Attempt 2

I also tried making dynamic optional as well:

class RemoteMessage {
  Notification? notification;
  Map<String, dynamic?>? data;
}

In that case, I get only 1 instance of the error:

Error: pigeons/push.dart:6: Generic type arguments must be nullable in field "data" in class "RemoteMessage".

Attempt 3

If I make the key type optional, i.e. Map<String?, dynamic>? data;, I get the error:

Unhandled exception:
FileSystemException: Cannot open file, path = './android/app/src/main/java/dev/flutter/pigeon/Pigeon.java' (OS Error: No such file or directory, errno = 2)
#0      _File.open.<anonymous closure> (dart:io/file_impl.dart:356:9)
<asynchronous suspension>
pub finished with exit code 255

Summary

It looks like Pigeon doesn't support Map or dynamic, although it should already support generics: #63468.

@ben-xD ben-xD changed the title Pigeon: Pigeon: using Maps Dec 5, 2021
@ben-xD ben-xD changed the title Pigeon: using Maps Pigeon: using Maps with dynamic Dec 5, 2021
@ben-xD ben-xD changed the title Pigeon: using Maps with dynamic Pigeon: using Maps Dec 5, 2021
@ben-xD ben-xD changed the title Pigeon: using Maps Pigeon: using Map Dec 5, 2021
@darshankawar darshankawar added the in triage Presently being triaged by the triage team label Dec 6, 2021
@darshankawar
Copy link
Member

@ben-xD
Can you provide flutter doctor -v ?
The package's readMe says below:

Screenshot 2021-12-06 at 2 27 54 PM

See if above points helps

@darshankawar darshankawar added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Dec 6, 2021
@ben-xD
Copy link
Author

ben-xD commented Dec 6, 2021

Hey @darshankawar

I re-read those points and they do not assist me 😊

Here is my flutter doctor:

[✓] Flutter (Channel stable, 2.5.3, on macOS 12.0.1 21A559 darwin-arm, locale en-GB)
    • Flutter version 2.5.3 at /opt/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 18116933e7 (7 weeks ago), 2021-10-15 10:46:35 -0700
    • Engine revision d3ea636dc5
    • Dart version 2.14.4

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Users/zen/Library/Android/sdk
    • Platform android-31, build-tools 31.0.0
    • Java binary at: /Users/zen/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/203.7784292/Android
      Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 13.1, Build version 13A1030d
    • CocoaPods version 1.11.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2020.3)
    • Android Studio at /Users/zen/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/203.7784292/Android
      Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)

[✓] Android Studio (version 2020.3)
    • Android Studio at /Users/zen/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/203.7784292/Android
      Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)

[✓] VS Code (version 1.62.3)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.29.0

[✓] Connected device (2 available)
    • iPhone SE BB🔫 (mobile) • 00008030-00044D301AD3402E • ios            • iOS 15.1 19B74
    • Chrome (web)            • chrome                    • web-javascript • Google Chrome 96.0.4664.55

• No issues found!

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Dec 6, 2021
@darshankawar
Copy link
Member

darshankawar commented Dec 7, 2021

Thanks for the update. I see the same behavior on latest stable and master.

stable, master flutter doctor -v
[✓] Flutter (Channel stable, 2.5.3, on Mac OS X 10.15.4 19E2269 darwin-x64,
    locale en-GB)
    • Flutter version 2.5.3 at /Users/dhs/documents/fluttersdk/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 18116933e7 (2 days ago), 2021-10-15 10:46:35 -0700
    • Engine revision d3ea636dc5
    • Dart version 2.14.4

[✓] Android toolchain - develop for Android devices (Android SDK version 30)
    • Android SDK at /Users/dhs/Library/Android/sdk
    • Platform android-30, build-tools 30.0.3
    • ANDROID_HOME = /Users/dhs/Library/Android/sdk
    • Java binary at: /Users/dhs/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/202.7486908/Android
      Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
    • All Android licenses accepted.    

[✓] Xcode - develop for iOS and macOS
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.3, Build version 12C33
    • CocoaPods version 1.10.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 4.1)
    • Android Studio at /Users/dhs/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/202.7486908/Android
      Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build
      1.8.0_242-release-1644-b3-6915495)        

[✓] VS Code (version 1.57.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.21.0

[✓] Connected device (4 available)
    • Darshan's iphone (mobile)  • 21150b119064aecc249dfcfe05e259197461ce23 •
      ios            • iOS 14.4.1 18D61
    • iPhone 12 Pro Max (mobile) • A5473606-0213-4FD8-BA16-553433949729     •
      ios            • com.apple.CoreSimulator.SimRuntime.iOS-14-3 (simulator)
    • macOS (desktop)            • macos                                    •
      darwin-x64     • Mac OS X 10.15.4 19E2269 darwin-x64
    • Chrome (web)               • chrome                                   •
      web-javascript • Google Chrome 93.0.4577.82


• No issues found!

[✓] Flutter (Channel master, 2.6.0-12.0.pre.934, on Mac OS X 10.15.4 19E2269
    darwin-x64, locale en-GB)
    • Flutter version 2.6.0-12.0.pre.934 at
      /Users/dhs/documents/fluttersdk/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision eea6c54dc2 (4 hours ago), 2021-12-06 16:59:05 -0800
    • Engine revision 66a281107b
    • Dart version 2.16.0 (build 2.16.0-80.0.dev)
    • DevTools version 2.9.1

[✓] Android toolchain - develop for Android devices (Android SDK version 30)
    • Android SDK at /Users/dhs/Library/Android/sdk
    • Platform android-30, build-tools 30.0.3
    • ANDROID_HOME = /Users/dhs/Library/Android/sdk
    • Java binary at: /Users/dhs/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/202.7486908/Android
      Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
    • All Android licenses accepted.    

[✓] Xcode - develop for iOS and macOS
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.5.1, Build version 12E507
    • CocoaPods version 1.10.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 4.1)
    • Android Studio at /Users/dhs/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/202.7486908/Android
      Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build
      1.8.0_242-release-1644-b3-6915495)        

[✓] VS Code (version 1.57.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.21.0

[[✓] Connected device (4 available)
    • Darshan's iphone (mobile)  • 21150b119064aecc249dfcfe05e259197461ce23 •
      ios            • iOS 14.4.1 18D61
    • iPhone 12 Pro Max (mobile) • A5473606-0213-4FD8-BA16-553433949729     •
      ios            • com.apple.CoreSimulator.SimRuntime.iOS-14-3 (simulator)
    • macOS (desktop)            • macos                                    •
      darwin-x64     • Mac OS X 10.15.4 19E2269 darwin-x64
    • Chrome (web)               • chrome                                   •
      web-javascript • Google Chrome 93.0.4577.82


• No issues found!


@darshankawar darshankawar added package flutter/packages repository. See also p: labels. p: pigeon related to pigeon messaging codegen tool found in release: 2.5 Found to occur in 2.5 found in release: 2.6 Found to occur in 2.6 has reproducible steps The issue has been confirmed reproducible and is ready to work on p: first party and removed in triage Presently being triaged by the triage team labels Dec 7, 2021
@darshankawar darshankawar changed the title Pigeon: using Map Pigeon: using Map or dynamic throws Generic type arguments must be nullable in field "data" error Dec 7, 2021
@stuartmorgan
Copy link
Contributor

I'm confused about what exactly this issue is intended to be about. What you have labelled attempts 1 and 2 are, as noted above, documented limitations in Pigeon at the moment.

As for attempt 3:

If I make the key type optional, i.e. Map<String?, dynamic>? data;, I get the error:

Unhandled exception:
FileSystemException: Cannot open file, path = './android/app/src/main/java/dev/flutter/pigeon/Pigeon.java' (OS Error: No such file or directory, errno = 2)
#0      _File.open.<anonymous closure> (dart:io/file_impl.dart:356:9)
<asynchronous suspension>
pub finished with exit code 255

This doesn't seem to have anything to do with Map, so I'm not sure how you concluded from this that Map isn't supported. Are you saying that you only get missing directory errors for the output file if you use Map? That seems very unlikely.

@darshankawar

I see the same behavior on latest stable and master.

Which of the behaviors did you verify?

@ben-xD
Copy link
Author

ben-xD commented Dec 7, 2021

are, as noted above, documented limitations in Pigeon at the moment.

Oh, I guess you're saying the key type of a Map should be optional too. That's confusing to me, what does a null key in a map actually mean?

Attempt 4:

After fixing the flutter pub run pigeon command, the Attempt 3 error is avoided, but a new error is generated. The current Pigeon now looks like:

class RemoteMessage {
  Notification? notification;
  Map<String?, dynamic>? data; // <-- This is line 5, referred to in the error
}

Giving an error:

Error: pigeons/push.dart:5: Generic type arguments must be nullable in field "data" in class "RemoteMessage".

What worked:

By adding ? to dynamic, it worked.

class RemoteMessage {
  Notification? notification;
  Map<String?, dynamic?>? data;
}

Thanks for your scrutiny @stuartmorgan, it looks like the code generation is completing now. I'll now test it at runtime.

@ben-xD
Copy link
Author

ben-xD commented Dec 7, 2021

I've closed this issue but created a new one because the generated code when using a Map<String?, dynamic?> is erroneous.

@darshankawar
Copy link
Member

Which of the behaviors did you verify?

@stuartmorgan I tried the Attempt1 and 2 which had resulted in same error messages as OP and hence labeled.

@darshankawar darshankawar added the r: invalid Issue is closed as not valid label Dec 8, 2021
@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 22, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
found in release: 2.5 Found to occur in 2.5 found in release: 2.6 Found to occur in 2.6 has reproducible steps The issue has been confirmed reproducible and is ready to work on p: pigeon related to pigeon messaging codegen tool package flutter/packages repository. See also p: labels. r: invalid Issue is closed as not valid
Projects
None yet
Development

No branches or pull requests

3 participants