Skip to content

flutter config silently accepts excess arguments caused by shell word splitting #121467

@gnprice

Description

@gnprice

Steps to Reproduce

Real-world version

  1. Try to follow the documented instructions for configuring Flutter with your Android Studio installation:

    Run flutter doctor to confirm that Flutter has located your installation of Android Studio. If Flutter cannot locate it, run flutter config --android-studio-dir <directory> to set the directory that Android Studio is installed to.

  2. Have Android Studio installed at a path that has a space character somewhere in it.

    If you're on Windows or macOS, this is the normal situation. It'll be at a path like C:\Program Files\something or /Applications/Android Studio someversion.app, respectively.

  3. Type the command literally as instructed. So if the path is /opt/My Android Studio, type:

    flutter config --android-studio-dir /opt/My Android Studio

    • (At this point, an expert command-line user knows they need to take care of the spaces by e.g. enclosing the path in quotes:

      flutter config --android-studio-dir "/opt/My Android Studio"

      But using Flutter generally doesn't and shouldn't require being a command-line expert.)

  4. Observe that flutter config seemed to accept the command, and move on.

  5. Run flutter doctor -v and observe that it doesn't recognize the Android Studio installation you tried to configure.

Expected behavior

The flutter config command fails with an error message. Instead of step 4, you notice something was wrong. This might cause you to remember you need quotes around spaces; if it doesn't, at least you're at the right step for debugging the problem.

Simplified version

  1. Run flutter config --android-studio-dir /opt/My Android Studio.

  2. Observe the output.

Expected Behavior

This flutter config command should give an error, because there are too many arguments.

Actual Behavior

The command cheerfully sets android-studio-dir in your Flutter settings to the value /opt/My:

$ flutter config --android-studio-dir /opt/My Android Studio
Setting "android-studio-dir" value to "/opt/My".

You may need to restart any open editors for them to read new settings.

It ignores that there are additional arguments "Android" and "Studio" that don't fit in the command's syntax.

If you had an actual Android Studio installation at /opt/My Android Studio which you wanted to use, this results in a broken Flutter configuration, because Flutter looks for Android Studio at the corrupted path /opt/My and doesn't find it.

In particular, if you wanted to use that Android Studio installation in order to use its bundled JDK, and the JDK you have installed elsewhere is too new for the Gradle version in the project you're working on, this results in an extremely confusing error like "Unsupported class file major version 61". (The fact that that error message is so bad is an issue in Gradle, not Flutter. But it worsens the impact of any Flutter tool issue that can lead to using the wrong JDK, including this issue.)

Related issues

Several previous reports have involved looking for Android Studio at a path that looks like it was the result of this issue.

Logs

Logs
$ flutter config --android-studio-dir /opt/My Android Studio
Setting "android-studio-dir" value to "/opt/My".

You may need to restart any open editors for them to read new settings.
$ flutter doctor -v
[✓] Flutter (Channel main, 3.8.0-16.0.pre.35, on Debian GNU/Linux 10 (buster) 4.19.0-23-amd64, locale en_US.UTF-8)
    • Flutter version 3.8.0-16.0.pre.35 on channel main at /home/greg/n/flutter/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 4811269379 (2 days ago), 2023-02-24 01:47:48 -0500
    • Engine revision 167c97bc3b
    • Dart version 3.0.0 (build 3.0.0-266.0.dev)
    • DevTools version 2.22.1

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
    • Android SDK at /home/greg/Android/Sdk
    • Platform android-33-ext4, build-tools 33.0.1
    • Java binary at: /home/greg/.nix-profile/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.5+8-nixos)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at google-chrome

[✓] Linux toolchain - develop for Linux desktop
    • clang version 7.0.1-8+deb10u2 (tags/RELEASE_701/final)
    • cmake version 3.13.4
    • ninja version 1.8.2
    • pkg-config version 0.29

[✓] Android Studio (version 2022.1)
    • Android Studio at /home/greg/lib/android-studio-2020.3.1.24
    • Flutter plugin version 72.1.2
    • Dart plugin version 221.6096
    • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301)

[!] Android Studio (version 2021.2)
    • Android Studio at /opt/android-studio
    • Flutter plugin version 71.1.2
    • Dart plugin version 212.5744
    ✗ Unable to find bundled Java version.
    • Try updating or re-installing Android Studio.

[✓] Android Studio (version 2022.2)
    • Android Studio at /home/greg/.local/share/JetBrains/Toolbox/apps/AndroidStudio/ch-0/222.4459.24.2221.9601061
    • Flutter plugin version 72.1.3
    • Dart plugin version 222.4533
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)

[!] Android Studio
    • Android Studio at /opt/My
    • 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
    ✗ android-studio-dir = /opt/My
    ✗ Android Studio not found at /opt/My
    • Try updating or re-installing Android Studio.
    • Consider removing your android-studio-dir setting by running:
      flutter config --android-studio-dir=

[✓] VS Code (version 1.75.1)
    • VS Code at /usr/share/code
    • Flutter extension can be installed from:
      🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[✓] Connected device (2 available)
    • Linux (desktop) • linux  • linux-x64      • Debian GNU/Linux 10 (buster) 4.19.0-23-amd64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 110.0.5481.77

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    found in release: 3.7Found to occur in 3.7found in release: 3.8Found to occur in 3.8has reproducible stepsThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer versiontoolAffects 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