Skip to content

[pigeon] "decode" casts fail in sound null-safe mode. #76405

Closed

Description

@ditman

Here's a Pigeon-generated class:

class PositionMessage {
  int? textureId;
  int? position;

  Object encode() {
    final Map<Object?, Object?> pigeonMap = <Object?, Object?>{};
    pigeonMap['textureId'] = textureId;
    pigeonMap['position'] = position;
    return pigeonMap;
  }

  static PositionMessage decode(Object message) {
    final Map<Object?, Object?> pigeonMap = message as Map<Object?, Object?>;
    return PositionMessage()
      ..textureId = pigeonMap['textureId'] as int
      ..position = pigeonMap['position'] as int;
  }
}

In sound null-safe mode, the decode method might have null values in textureId and position, so the cast as int fails:

type 'Null' is not a subtype of type 'int' in type cast
  package:video_player_platform_interface/messages.dart 121:44  PositionMessage.decode
  package:video_player_platform_interface/messages.dart 339:30  VideoPlayerApi.position

Shouldn't the as casts match the type of the attribute they're casting to? if int? textureId, shouldn't the decode cast to: as int?

Steps to Reproduce

Attempt to run the video_player_platform_interface tests in null-safe mode (flutter channel master, for example):

  1. Clone this branch: https://github.com/ditman/plugins/tree/reversion-video_player_platform_interface-as-preview
  2. cd YOUR_CLONE/packages/video_player/video_player_platform_interface
  3. flutter test

Expected results:

All tests pass.

Actual results:

Some tests fail with the error described in this issue.

Activity

  1. ditman commented on Feb 19, 2021

    @ditman
    MemberAuthor
  2. ditman commented on Feb 19, 2021

    @ditman
    MemberAuthor

    This seems to be only affecting tests (for now) because of this:

    https://github.com/flutter/plugins/blob/master/packages/video_player/video_player_platform_interface/lib/test.dart#L48

    The message to decode might be incomplete.

  3. added
    in triagePresently being triaged by the triage team
    p: pigeonrelated to pigeon messaging codegen tool
    a: null-safetySupport for Dart's null safety feature
    a: tests"flutter test", flutter_test, or one of our tests
    toolAffects the "flutter" command-line tool. See also t: labels.
    and removed
    in triagePresently being triaged by the triage team
    on Feb 22, 2021
  4. removed
    toolAffects the "flutter" command-line tool. See also t: labels.
    on Feb 23, 2021
  5. xster commented on Apr 16, 2021

    @xster
    Member

    @gaaclarke this is fixed now right?

  6. gaaclarke commented on Apr 16, 2021

    @gaaclarke
    Member
  7. github-actions commented on Aug 2, 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.

  8. locked as resolved and limited conversation to collaborators on Aug 2, 2021
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

    a: null-safetySupport for Dart's null safety featurea: tests"flutter test", flutter_test, or one of our testsp: 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