Skip to content

[web]: Unicode char throws Bad UTF-8 encoding (U+FFFD; REPLACEMENT CHARACTER) error #137025

Closed as not planned

Description

@d-polikhranidi

Is there an existing issue for this?

Steps to reproduce

I have searched that there were similar issues but they are closed without any fix. I suppose that error in Flutter debug console in Android Studio or something related with this. I suppose so because there's no any issues with rendering such special characters but only if there appears in console (you can see this in attached video)

Second, I think the problem is wrong conversion from special char (in my case �) to bytes ([239, 191, 189, 10] but it must be [239, 191, 189]).

There's no any problems in release mode or if I go to localhost from other browser instance which is not connected to Flutter debugger. But using other instance of browser is not a solution because it makes development very difficult in such circumstances))

To reproduce just start my example code

Expected results

Flutter debugger shows � in console

Actual results

App crashes

Code sample

Code sample
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});
  @override
  Widget build(BuildContext context) {

    const String crashString = "�";

    return MaterialApp(
      title: 'App crasher',
      home: Center(
        child: TextButton(onPressed: () => print(crashString), child: const Text("Crash app")),
      ),
    );
  }
}

Screenshots or Video

Screenshots / Video demonstration
37484d2d-7302-406a-87f3-f8b81dbd843b.mp4

Logs

Logs
Launching lib/main.dart on Chrome in debug mode...
Waiting for connection from debug service on Chrome...
This app is linked to the debug service: ws://127.0.0.1:54270/2-5SauS8BYM=/ws
Debug service listening on ws://127.0.0.1:54270/2-5SauS8BYM=/ws
Debug service listening on ws://127.0.0.1:54270/2-5SauS8BYM=/ws
Finished with error: Bad UTF-8 encoding (U+FFFD; REPLACEMENT CHARACTER) found while decoding string: �
. The Flutter team would greatly appreciate if you could file a bug explaining exactly what you were doing when this happened:
https://github.com/flutter/flutter/issues/new/choose
The source bytes were:
[239, 191, 189, 10]

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.13.8, on macOS 14.0 23A344 darwin-arm64, locale ru-BY)
    • Flutter version 3.13.8 on channel stable at /Users/admin/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 6c4930c4ac (3 days ago), 2023-10-18 10:57:55 -0500
    • Engine revision 767d8c75e8
    • Dart version 3.1.4
    • DevTools version 2.25.0

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
    • Android SDK at /Users/admin/Library/Android/sdk
    • Platform android-33, build-tools 33.0.2
    • Java binary at: /Users/admin/Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.0.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15A507
    • CocoaPods version 1.12.1

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

[✓] Android Studio (version 2022.3)
    • Android Studio at /Users/admin/Applications/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 17.0.6+0-17.0.6b829.9-10027231)

[✓] Connected device (3 available)
    • iPhone (mobile) • 00008030-00125C940292802E • ios            • iOS 17.0.3 21A360
    • macOS (desktop) • macos                     • darwin-arm64   • macOS 14.0 23A344 darwin-arm64
    • Chrome (web)    • chrome                    • web-javascript • Google Chrome 118.0.5993.96

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

• No issues found!

Activity

  1. d-polikhranidi commented on Oct 22, 2023

    @d-polikhranidi
    Author

    Aha, I found from where this error rises: https://github.com/flutter/flutter/blob/master/packages/flutter_tools/lib/src/convert.dart#L60

    I believe that � not indicates malformed input.

  2. LucyJeong commented on Oct 22, 2023

    @LucyJeong

    @d-polikhranidi How to fix it? just remove � char?? or handling � char??

  3. d-polikhranidi commented on Oct 22, 2023

    @d-polikhranidi
    Author

    @d-polikhranidi How to fix it? just remove � char?? or handling � char??

    if you experiencing problems only in print function (output inside your console) just use log instead of print

  4. darshankawar commented on Oct 23, 2023

    @darshankawar
    Member

    Thanks for the report. I see that the reported error occurs only on web, as it works as expected on mobile and desktop.

    1. On web:
    Bad UTF-8 encoding (U+FFFD; REPLACEMENT CHARACTER) found while decoding string: �
    . The Flutter team would greatly appreciate if you could file a bug explaining exactly what you were doing when this happened:
    https://github.com/flutter/flutter/issues/new/choose
    The source bytes were:
    [239, 191, 189, 10]
    
    
    1. On mobile and desktop:
    2023-10-23 13:15:58.992136+0530 Runner[10743:121715] flutter: �
    2023-10-23 13:16:02.315964+0530 Runner[10743:121715] flutter: �
    2023-10-23 13:16:03.340706+0530 Runner[10743:121715] flutter: �
    2023-10-23 13:16:04.818441+0530 Runner[10743:121715] flutter: �
    
    
    stable, master flutter doctor -v
    [!] Flutter (Channel stable, 3.13.8, on macOS 12.2.1 21D62 darwin-x64, locale
        en-GB)
        • Flutter version 3.13.8 on channel stable at
          /Users/dhs/documents/fluttersdk/flutter
        ! Warning: `flutter` on your path resolves to
          /Users/dhs/Documents/Fluttersdk/flutter/bin/flutter, which is not inside
          your current Flutter SDK checkout at
          /Users/dhs/documents/fluttersdk/flutter. Consider adding
          /Users/dhs/documents/fluttersdk/flutter/bin to the front of your path.
        ! Warning: `dart` on your path resolves to
          /Users/dhs/Documents/Fluttersdk/flutter/bin/dart, which is not inside your
          current Flutter SDK checkout at /Users/dhs/documents/fluttersdk/flutter.
          Consider adding /Users/dhs/documents/fluttersdk/flutter/bin to the front
          of your path.
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 6c4930c4ac (5 days ago), 2023-10-18 10:57:55 -0500
        • Engine revision 767d8c75e8
        • Dart version 3.1.4
        • DevTools version 2.25.0
        • If those were intentional, you can disregard the above warnings; however
          it is recommended to use "git" directly to perform update checks and
          upgrades.
    
    [!] Xcode - develop for iOS and macOS (Xcode 12.3)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        ! Flutter recommends a minimum Xcode version of 13.
          Download the latest version or update via the Mac App Store.
        • CocoaPods version 1.11.2
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] VS Code (version 1.62.0)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.21.0
    
    [✓] Connected device (5 available)
        • SM G975F (mobile)       • RZ8M802WY0X • android-arm64   • Android 11 (API 30)
        • 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 98.0.4758.80
    
    [✓] HTTP Host Availability
        • All required HTTP hosts are available
    
    ! Doctor found issues in 1 category.
    
    [!] Flutter (Channel master, 3.16.0-15.0.pre.1, on macOS 12.2.1 21D62
        darwin-x64, locale en-GB)
        • Flutter version 3.16.0-15.0.pre.1 on channel master at
          /Users/dhs/documents/fluttersdk/flutter
        ! Warning: `flutter` on your path resolves to
          /Users/dhs/Documents/Fluttersdk/flutter/bin/flutter, which is not inside
          your current Flutter SDK checkout at
          /Users/dhs/documents/fluttersdk/flutter. Consider adding
          /Users/dhs/documents/fluttersdk/flutter/bin to the front of your path.
        ! Warning: `dart` on your path resolves to
          /Users/dhs/Documents/Fluttersdk/flutter/bin/dart, which is not inside your
          current Flutter SDK checkout at /Users/dhs/documents/fluttersdk/flutter.
          Consider adding /Users/dhs/documents/fluttersdk/flutter/bin to the front
          of your path.
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision eefafdacdb (3 days ago), 2023-10-20 00:06:34 -0400
        • Engine revision 9dd59f7fcf
        • Dart version 3.3.0 (build 3.3.0-45.0.dev)
        • DevTools version 2.28.1
        • If those were intentional, you can disregard the above warnings; however
          it is recommended to use "git" directly to perform update checks and
          upgrades.
    
    [!] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
        • Android SDK at /Users/dhs/Library/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/macos#android-setup for
          more details.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Build 13C100
        • CocoaPods version 1.11.2
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] IntelliJ IDEA Ultimate Edition (version 2021.3.2)
        • IntelliJ at /Applications/IntelliJ IDEA.app
        • Flutter plugin version 65.1.4
        • Dart plugin version 213.7228
    
    [✓] VS Code (version 1.62.0)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.29.0
    
    [✓] Connected device (3 available)
        • Darshan's iphone (mobile) • 21150b119064aecc249dfcfe05e259197461ce23 • ios
          • iOS 15.3.1 19D52
        • macOS (desktop)           • macos                                    •
          darwin-x64     • macOS 12.2.1 21D62 darwin-x64
        • Chrome (web)              • chrome                                   •
          web-javascript • Google Chrome 109.0.5414.119
    
    [✓] Network resources
        • All expected network resources are available.
    
    ! Doctor found issues in 1 category.
          
    [!] Xcode - develop for iOS and macOS (Xcode 12.3)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        ! Flutter recommends a minimum Xcode version of 13.
          Download the latest version or update via the Mac App Store.
        • CocoaPods version 1.11.2
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] VS Code (version 1.62.0)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.21.0
    
    [✓] Connected device (5 available)
        • SM G975F (mobile)       • RZ8M802WY0X • android-arm64   • Android 11 (API 30)
        • 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 98.0.4758.80
    
    [✓] HTTP Host Availability
        • All required HTTP hosts are available
    
    ! Doctor found issues in 1 category.
    
    
    
    
  5. added
    toolAffects the "flutter" command-line tool. See also t: labels.
    platform-webWeb applications specifically
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    c: crashStack traces logged to the console
    team-toolOwned by Flutter Tool team
    fyi-webFor the attention of Web platform team
    and removed
    in triagePresently being triaged by the triage team
    on Oct 23, 2023
  6. changed the title [-][web, maybe all platfroms / flutter debugger] Bad UTF-8 encoding (U+FFFD; REPLACEMENT CHARACTER)[/-] [+][web]: Unicode char throws `Bad UTF-8 encoding (U+FFFD; REPLACEMENT CHARACTER)` error[/+] on Oct 23, 2023
  7. 9 remaining items

  8. removed
    fyi-webFor the attention of Web platform team
    on Nov 2, 2023
  9. ditman commented on Nov 2, 2023

    @ditman
    Member

    The exception comes from here:

    • String convert(List<int> input, [int start = 0, int? end]) {
      final String result = _systemDecoder.convert(input, start, end);
      // Finding a Unicode replacement character indicates that the input
      // was malformed.
      if (reportErrors && result.contains('\u{FFFD}')) {
      throwToolExit(
      'Bad UTF-8 encoding (U+FFFD; REPLACEMENT CHARACTER) found while decoding string: $result. '
      'The Flutter team would greatly appreciate if you could file a bug explaining '
      'exactly what you were doing when this happened:\n'
      'https://github.com/flutter/flutter/issues/new/choose\n'
      'The source bytes were:\n$input\n\n');
      }
      return result;
      }

    It seems the flutter tool has its own Utf8 codec that may be configured to log this error or not, right before throwing (I wonder if it can be configured to remove these weird characters, or replace them by a tofu box □ instead, so the app can continue)

    Other reports:

    (Some similar reports come from vscode info being written to the log, but that seems to have been fixed by adding the initial configurability to the codec, see git blame for reportErrors)

  10. nvbien2000 commented on Apr 9, 2024

    @nvbien2000
  11. grobarko commented on Jul 30, 2024

    @grobarko
  12. andrewkolos commented on Jul 30, 2024

    @andrewkolos
    Contributor

    Per https://github.com/flutter/flutter/blob/master/docs/contributing/issue_hygiene/README.md#when-will-my-bug-be-fixed, please don't ask for updates. Such comments ultimately slow down work on the project. Instead, consider adding a +1 reaction on the top level comment.

    Any updates will be posted as they are available, or the issue will have an assignee if it's being worked on. As always, anyone is welcome to submit their own pull request to resolve the issue.

  13. x544D commented on Nov 30, 2024

    @x544D
  14. github-actions commented on Jul 28, 2025

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

  15. locked as resolved and limited conversation to collaborators on Jul 28, 2025
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

    P2Important issues not at the top of the work listc: crashStack traces logged to the consolefound in release: 3.13Found to occur in 3.13found in release: 3.16Found to occur in 3.16has reproducible stepsThe issue has been confirmed reproducible and is ready to work onplatform-webWeb applications specificallyr: invalidIssue is closed as not validteam-toolOwned by Flutter Tool teamtoolAffects the "flutter" command-line tool. See also t: labels.triaged-toolTriaged by Flutter Tool team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions