Skip to content

[tool_crash] _TypeError: (#0 AppResourceBundle.translationFor (package:flutter_tools/src/localizations/gen_l10n_types.dart:637:70)) #138297

Closed

Description

@Meshavegas

Command

flutter --no-color run --machine --track-widget-creation --device-id=OF6LHMB9A2101175 --start-paused --dart-define=flutter.inspector.structuredErrors=true lib\main.dart

Steps to Reproduce

  1. ...
  2. ...
  3. ...

Logs

_TypeError: (#0 AppResourceBundle.translationFor (package:flutter_tools/src/localizations/gen_l10n_types.dart:637:70))

#0      AppResourceBundle.translationFor (package:flutter_tools/src/localizations/gen_l10n_types.dart:637:70)
#1      new Message (package:flutter_tools/src/localizations/gen_l10n_types.dart:353:42)
#2      LocalizationsGenerator.loadResources.<anonymous closure> (package:flutter_tools/src/localizations/gen_l10n.dart:908:67)
#3      MappedIterator.moveNext (dart:_internal/iterable.dart:393:20)
#4      new _GrowableList._ofOther (dart:core-patch/growable_array.dart:202:26)
#5      new _GrowableList.of (dart:core-patch/growable_array.dart:152:26)
#6      new List.of (dart:core-patch/array_patch.dart:47:28)
#7      Iterable.toList (dart:core/iterable.dart:495:7)
#8      LocalizationsGenerator.loadResources (package:flutter_tools/src/localizations/gen_l10n.dart:910:8)
#9      generateLocalizations (package:flutter_tools/src/localizations/gen_l10n.dart:73:9)
#10     GenerateLocalizationsTarget.build (package:flutter_tools/src/build_system/targets/localizations.dart:60:11)
#11     _BuildInstance._invokeInternal (package:flutter_tools/src/build_system/build_system.dart:853:27)
<asynchronous suspension>
#12     FlutterBuildSystem.build (package:flutter_tools/src/build_system/build_system.dart:620:16)
<asynchronous suspension>
#13     generateLocalizationsSyntheticPackage (package:flutter_tools/src/dart/generate_synthetic_packages.dart:56:30)
<asynchronous suspension>
#14     FlutterCommand.verifyThenRunCommand (package:flutter_tools/src/runner/flutter_command.dart:1592:7)
<asynchronous suspension>
#15     FlutterCommand.run.<anonymous closure> (package:flutter_tools/src/runner/flutter_command.dart:1297:27)
<asynchronous suspension>
#16     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
<asynchronous suspension>
#17     CommandRunner.runCommand (package:args/command_runner.dart:212:13)
<asynchronous suspension>
[✓] Flutter (Channel stable, 3.13.8, on Microsoft Windows [Version 10.0.22621.2506], locale en-GB)
    • Flutter version 3.13.8 on channel stable at D:\Flutter\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 6c4930c4ac (3 weeks ago), 2023-10-18 10:57:55 -0500
    • Engine revision 767d8c75e8
    • Dart version 3.1.4
    • DevTools version 2.25.0

[✓] Windows Version (Installed version of Windows is version 10 or higher)

[!] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at C:\Users\Administrator\AppData\Local\Android\sdk
    ✗ cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/windows#android-setup for more details.

[✓] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[✗] Visual Studio - develop Windows apps
    ✗ Visual Studio not installed; this is necessary to develop Windows apps.
      Download at https://visualstudio.microsoft.com/downloads/.
      Please install the "Desktop development with C++" workload, including all of its default components

[✓] Android Studio (version 2022.3)
    • Android Studio at C:\Program Files\Android\Android Studio
    • 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 17.0.6+0-b2043.56-10027231)

[✓] IntelliJ IDEA Ultimate Edition (version 2023.1)
    • IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA 2023.1.2
    • 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

[✓] VS Code (version 1.84.1)
    • VS Code at C:\Users\Administrator\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.76.0

[✓] Connected device (4 available)
    • SHV46 (mobile)    • OF6LHMB9A2101175 • android-arm64  • Android 11 (API 30)
    • Windows (desktop) • windows          • windows-x64    • Microsoft Windows [Version 10.0.22621.2506]
    • Chrome (web)      • chrome           • web-javascript • Google Chrome 118.0.5993.88
    • Edge (web)        • edge             • web-javascript • Microsoft Edge 119.0.2151.58

[✓] Network resources
    • All expected network resources are available.

! Doctor found issues in 2 categories.

Flutter Application Metadata

Type: malformed
Version: 1.0.0+1
Material: true
Android X: false
Module: false
Plugin: false
Android package: null
iOS bundle identifier: null
Creation channel: null
Creation framework version: null

Plugins

firebase_core-2.22.0
firebase_core_web-2.8.1
firebase_messaging-14.7.4
firebase_messaging_web-3.5.13
flutter_native_select-1.0.1
flutter_native_splash-2.2.19
path_provider_linux-2.2.1
path_provider_windows-2.2.1
restart_app-1.2.1
shared_preferences-2.1.0
shared_preferences_android-2.2.1
shared_preferences_foundation-2.3.4
shared_preferences_linux-2.3.2
shared_preferences_web-2.2.1
shared_preferences_windows-2.3.2

Activity

  1. danagbemava-nc commented on Nov 13, 2023

    @danagbemava-nc
    Member

    Labeling based on the report above.

  2. added
    c: crashStack traces logged to the console
    toolAffects the "flutter" command-line tool. See also t: labels.
    a: internationalizationSupporting other languages or locales. (aka i18n)
    team-toolOwned by Flutter Tool team
    and removed
    in triagePresently being triaged by the triage team
    on Nov 13, 2023
  3. Meshavegas commented on Nov 15, 2023

    @Meshavegas
    Author

    Thank you but i solved it. :)

  4. andrewkolos commented on Nov 15, 2023

    @andrewkolos
    Contributor

    Thank you but i solved it. :)

    @Meshavegas, I'm glad you were able solve whatever was causing this crash 🙂. Still, the flutter CLI tool should never crash, which probably means you encountered a bug. I would like to find that bug. If you are willing and able, could you share what was causing this crash?

  5. Meshavegas commented on Nov 16, 2023

    @Meshavegas
    Author

    Thank you but i solved it. :)

    @Meshavegas, I'm glad you were able solve whatever was causing this crash 🙂. Still, the flutter CLI tool should never crash, which probably means you encountered a bug. I would like to find that bug. If you are willing and able, could you share what was causing this crash?

    It appears that the Flutter CLI crash i encountered might have been triggered by a shortage of disk space on my computer. I point out that the substantial resources consumption by Android Studio, when in use, could be a contributing factor to the Flutter CLI crash.

    In summary, my hypothesis is that the insufficient disk space, potentially exacerbated by the resource demands of Android Studio, could have led to the instability of the Flutter CLI.
    I solved the issue by either freeing up space and upgrading my storage capacity might be a practical step to mitigate such problems in the future.

  6. andrewkolos commented on Nov 27, 2023

    @andrewkolos
    Contributor

    I've finally done some digging here. Here's what I found.

    My reading of the stack trace:

    • #⁠8: LocalizationsGenerator.loadResources: During build, we read the app's arb files (each of which contains JSON containing resource-value pairs for various locales).
    • #⁠2/#⁠1: Per each resourceId (key) in the template ARB file, we look for a corresponding entry in the rest of the ARB files.
      Here's the line where the TypeError happens:
    • #⁠0: AppResourceBundle.translationFor: in one of those ARB files, we lookup the translation for the given resourceId from a Map<String, Object?>. We try to cast this to a String?. Here is that line of code:

    String? translationFor(String resourceId) => resources[resourceId] as String?;

    The indexing operation here shouldn't result in a TypeError, so I'm thinking that resources[resourceId] must be non-null and also not a String. resources is generated during the construction of the AppResourceBundle by a simple json.decode operation, and I don't see any code that could overwrite any values. This leads me to believe that flutter was trying to work with an invalid ARB file. To test this, I tried making a minimal repro, and I was successful.

    1. Create a copy of the Flutter website's gen_l10n_example.
    2. In lib/l10n/app_es.arb, change the helloWorld entry's value from "¡Hola Mundo!" to {}.
    3. flutter clean and flutter pub get (which will run flutter gen_l10n).

    This resulted in a crash containing a link to create a new GitHub issue that looked identical to this issue. Here is my stack trace:

    Details

    _TypeError: (#0 AppResourceBundle.translationFor (package:flutter_tools/src/localizations/gen_l10n_types.dart:649:70))

    #0      AppResourceBundle.translationFor (package:flutter_tools/src/localizations/gen_l10n_types.dart:649:70)
    #1      new Message (package:flutter_tools/src/localizations/gen_l10n_types.dart:354:42)
    #2      LocalizationsGenerator.loadResources.<anonymous closure> (package:flutter_tools/src/localizations/gen_l10n.dart:913:67)
    #3      MappedIterator.moveNext (dart:_internal/iterable.dart:403:20)
    #4      new _GrowableList._ofOther (dart:core-patch/growable_array.dart:202:26)
    #5      new _GrowableList.of (dart:core-patch/growable_array.dart:152:26)
    #6      new List.of (dart:core-patch/array_patch.dart:39:18)
    #7      Iterable.toList (dart:core/iterable.dart:497:7)
    #8      LocalizationsGenerator.loadResources (package:flutter_tools/src/localizations/gen_l10n.dart:921:8)
    #9      generateLocalizations (package:flutter_tools/src/localizations/gen_l10n.dart:77:9)
    #10     GenerateLocalizationsTarget.build (package:flutter_tools/src/build_system/targets/localizations.dart:60:11)
    #11     _BuildInstance._invokeInternal (package:flutter_tools/src/build_system/build_system.dart:853:27)
    <asynchronous suspension>
    #12     FlutterBuildSystem.build (package:flutter_tools/src/build_system/build_system.dart:620:16)
    <asynchronous suspension>
    #13     generateLocalizationsSyntheticPackage (package:flutter_tools/src/dart/generate_synthetic_packages.dart:56:30)
    <asynchronous suspension>
    #14     PackagesGetCommand.runCommand (package:flutter_tools/src/commands/packages.dart:305:9)
    <asynchronous suspension>
    #15     FlutterCommand.run.<anonymous closure> (package:flutter_tools/src/runner/flutter_command.dart:1388:27)
    <asynchronous suspension>
    #16     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:153:19)
    <asynchronous suspension>
    #17     CommandRunner.runCommand (package:args/command_runner.dart:212:13)
    <asynchronous suspension>
    

    In conclusion, when parsing arb files, flutter should also validate the contents. If the contents are invalid, we it throw a ToolExit with a helpful message instead of crashing. I've opened #139035 to do this

  7. github-actions commented on Dec 12, 2023

    @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 Dec 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

a: internationalizationSupporting other languages or locales. (aka i18n)c: crashStack traces logged to the consoler: fixedIssue is closed as already fixed in a newer versionteam-toolOwned by Flutter Tool teamtoolAffects the "flutter" command-line tool. See also t: labels.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions