Skip to content

[pigeon] crash using a nested class who isn't referenced in an API directly #58896

Closed

Description

@xster

No crash:

import 'package:pigeon/pigeon.dart';

class Book {
  String title;
  String subtitle;
  String author;
  String publishDate;
  int pageCount;
//  Thumbnail thumbnail;
}

// class Thumbnail {
//  String url;
// }

@HostApi()
abstract class HostBookApi {
  Book getEditedBook();
}

Crash:

import 'package:pigeon/pigeon.dart';

class Book {
  String title;
  String subtitle;
  String author;
  String publishDate;
  int pageCount;
  Thumbnail thumbnail;
}

class Thumbnail {
  String url;
}

@HostApi()
abstract class HostBookApi {
  Book getEditedBook();
}

from running

flutter pub run pigeon --input pigeon/idl.dart --dart_out lib/api.dart --java_out ../android_books/app/src/main/java/dev/flutter/example/books/Api.java --java_package "dev.flutter.example.books"

Unhandled exception:
NoSuchMethodError: The getter 'datatype' was called on null.
Receiver: null
Tried calling: datatype
#0      Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
#1      generateJava.<anonymous closure>.<anonymous closure> (package:pigeon/java_generator.dart:224:50)
#2      Indent.scoped (package:pigeon/generator_tools.dart:71:9)
#3      generateJava.<anonymous closure> (package:pigeon/java_generator.dart:220:14)
#4      Indent.scoped (package:pigeon/generator_tools.dart:71:9)
#5      generateJava (package:pigeon/java_generator.dart:214:10)
#6      Pigeon.run.<anonymous closure> (package:pigeon/pigeon_lib.dart:364:17)
#7      Pigeon._runGenerator (package:pigeon/pigeon_lib.dart:270:9)
#8      Pigeon.run (package:pigeon/pigeon_lib.dart:361:15)
<asynchronous suspension>
#9      main (file:///Users/xster/development/samples/add_to_app/flutter_module_books/_pigeon_temp_.dart:7:21)
#10     _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:299:32)
#11     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12)

cc @gaaclarke

Activity

  1. added
    packageflutter/packages repository. See also p: labels.
    on Jun 7, 2020
  2. xster commented on Jun 8, 2020

    @xster
    MemberAuthor

    looking at the current list for pigeon, I think this one is likely the highest priority? WDYT?

  3. gaaclarke commented on Jun 12, 2020

    @gaaclarke
    Member

    This is an ordering issue because Thumbnail is used before it is defined. That's not how Dart typically works so I'll see if I can make the parser smarter.

  4. changed the title [-][pigeon] java generator crashes when using nested class[/-] [+][pigeon] crash when using a nested class before it is defined[/+] on Jun 12, 2020
  5. xster commented on Jun 12, 2020

    @xster
    MemberAuthor

    You're saying if I flipped the definition it would work? :D

  6. gaaclarke commented on Jun 12, 2020

    @gaaclarke
    Member

    Yep, i'm also going to make that error easier to understand in case someone mistypes a class name.

  7. xster commented on Jun 12, 2020

    @xster
    MemberAuthor

    Yep, i'm also going to make that error easier to understand in case someone mistypes a class name.

    That's just #58897 right?

  8. gaaclarke commented on Jun 12, 2020

    @gaaclarke
    Member

    @xster Yep, should be. I'm going to cover it to be sure.

  9. gaaclarke commented on Jun 12, 2020

    @gaaclarke
    Member

    Wait i'm wrong about the ordering, my bad. I saw one work in the other order and I... assumed :*(

  10. gaaclarke commented on Jun 12, 2020

    @gaaclarke
    Member

    This is the actual issue, Thumbnail is never referenced in the API directly so it isn't parsed, this works:

    import 'package:pigeon/pigeon.dart';
    
    class Book {
      String title;
      String subtitle;
      String author;
      String publishDate;
      int pageCount;
      Thumbnail thumbnail;
    }
    
    class Thumbnail {
      String url;
    }
    
    @HostApi()
    abstract class HostBookApi {
      Book getEditedBook();
      Thumbnail foo();
    }

    I just have to make the parsing of nested classes recurse.

  11. changed the title [-][pigeon] crash when using a nested class before it is defined[/-] [+][pigeon] crash using a nested class who isn't referenced in an API directly[/+] on Jun 12, 2020
  12. github-actions commented on Aug 20, 2021

    @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.

  13. locked as resolved and limited conversation to collaborators on Aug 20, 2021
  14. added
    P0Critical issues such as a build break or regression
    and removed on Jun 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P0Critical issues such as a build break or regressionp: pigeonrelated to pigeon messaging codegen toolpackageflutter/packages repository. See also p: labels.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions