Skip to content

Redact SDK path in FlutterApp command log - #9203

Merged
jwren merged 3 commits into
flutter:mainfrom
jwren:8566
Nov 4, 2026
Merged

jwren merged 3 commits into
flutter:mainfrom
jwren:8566

Conversation

@jwren

@jwren jwren commented Nov 3, 2026

Copy link
Copy Markdown
Member

Promote FlutterCommand.safeCommandLog to public static (using

PluginLogger.isFilePathLoggingEnabled and PathUtil.getFileName) and use

it when logging the command line in FlutterApp.start().

Coverage verified with Kover:

  • FlutterCommand.safeCommandLog: 100% line/branch coverage (3/3 lines)

  • FlutterApp.getCommandLog: 100% line coverage (2/2 lines)

Fixes #8566

Promote FlutterCommand.safeCommandLog to public static (using

PluginLogger.isFilePathLoggingEnabled and PathUtil.getFileName) and use

it when logging the command line in FlutterApp.start().

Coverage verified with Kover:

- FlutterCommand.safeCommandLog: 100% line/branch coverage (3/3 lines)

- FlutterApp.getCommandLog: 100% line coverage (2/2 lines)

Fixes flutter#8566
@jwren
jwren requested review from helin24 and pq as code owners November 3, 2026 06:31
@jwren
jwren marked this pull request as draft November 3, 2026 06:31

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request implements redaction of the Flutter SDK path when logging command lines in FlutterApp if file path logging is disabled. It refactors FlutterCommand.safeCommandLog to be static and public, and integrates it into FlutterApp logging, accompanied by new unit tests. The review feedback suggests defensive handling of potential null values in commandLine.getExePath() to avoid NullPointerExceptions, and recommends removing a redundant static delegation method in FlutterApp to simplify the API.


final Path path = Path.of(commandLine.getExePath());
return path.getFileName() + " " + commandLine.getParametersList();
return PathUtil.getFileName(commandLine.getExePath()) + " " + commandLine.getParametersList();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

[CONCERN] To prevent potential NullPointerExceptions during logging, we should defensively handle the case where commandLine.getExePath() returns null. Logging utilities should be extremely robust and never throw exceptions that could disrupt the main application flow.

    String exePath = commandLine.getExePath();
    String exeName = exePath != null ? PathUtil.getFileName(exePath) : "";
    return exeName + " " + commandLine.getParametersList();
References
  1. Ensure robust and defensive code to prevent unexpected runtime exceptions. (link)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PathUtil.getFileName(@Nullable String) is already null-safe in the IntelliJ SDK (returning "" for null or empty strings), and GeneralCommandLine.getExePath() is annotated @NotNull, so an explicit null check here is redundant.

Comment on lines +191 to +213
/**
* Returns a log-safe string representation of the app's command line, redacting the SDK path
* when file path logging is disabled.
* <p>
* Exposed for testing.
*/
@VisibleForTesting
@NotNull
public String getCommandLog() {
return getCommandLog(myCommand);
}

/**
* Returns a log-safe string representation of the given command line, redacting the SDK path
* when file path logging is disabled.
* <p>
* Exposed for testing.
*/
@VisibleForTesting
@NotNull
public static String getCommandLog(@NotNull GeneralCommandLine command) {
return FlutterCommand.safeCommandLog(command);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

[CONCERN] The static getCommandLog(GeneralCommandLine) method in FlutterApp is a redundant delegation to FlutterCommand.safeCommandLog(command). We can simplify the API surface of FlutterApp by removing this static method and having the instance getCommandLog() call FlutterCommand.safeCommandLog(myCommand) directly.

Suggested change
/**
* Returns a log-safe string representation of the app's command line, redacting the SDK path
* when file path logging is disabled.
* <p>
* Exposed for testing.
*/
@VisibleForTesting
@NotNull
public String getCommandLog() {
return getCommandLog(myCommand);
}
/**
* Returns a log-safe string representation of the given command line, redacting the SDK path
* when file path logging is disabled.
* <p>
* Exposed for testing.
*/
@VisibleForTesting
@NotNull
public static String getCommandLog(@NotNull GeneralCommandLine command) {
return FlutterCommand.safeCommandLog(command);
}
/**
* Returns a log-safe string representation of the app's command line, redacting the SDK path
* when file path logging is disabled.
* <p>
* Exposed for testing.
*/
@VisibleForTesting
@NotNull
public String getCommandLog() {
return FlutterCommand.safeCommandLog(myCommand);
}
References
  1. Avoid redundant delegation methods to keep the codebase clean and maintainable. (link)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 1590d7c. Removed the redundant static getCommandLog(GeneralCommandLine) helper and delegated getCommandLog() directly to FlutterCommand.safeCommandLog(myCommand).

throws ExecutionException {
LOG.info(analyticsStart + " " + project.getName() + " (" + mode.mode() + ")");
LOG.info(command.toString());
LOG.info(getCommandLog(command));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

[CONCERN] Since we can remove the redundant static getCommandLog method, we should call FlutterCommand.safeCommandLog(command) directly here.

Suggested change
LOG.info(getCommandLog(command));
LOG.info(FlutterCommand.safeCommandLog(command));
References
  1. Avoid redundant delegation methods to keep the codebase clean and maintainable. (link)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 1590d7c. Updated FlutterApp.start to call FlutterCommand.safeCommandLog(command) directly.

Inline FlutterApp.getCommandLog(GeneralCommandLine) so that the instance
getCommandLog() and FlutterApp.start(...) delegate directly to
FlutterCommand.safeCommandLog(...) per PR review feedback.

Verified with FlutterAppTest and FlutterCommandTest.

Issue: flutter#8566
@jwren
jwren marked this pull request as ready for review November 3, 2026 18:24
*/
@VisibleForTesting
@NotNull
public String getCommandLog() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LLM caught nit: now that safeCommandLog is public and tested directly in FlutterCommandTest, this test-only getter (and the FlutterAppTest cases) don't add much. They wouldn't catch start() going back to command.toString(). Drop them?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 4aa8d4e — removed the test-only getCommandLog() getter from FlutterApp and the duplicate test cases in FlutterAppTest.

Comment thread CHANGELOG.md Outdated

### Changed
- Centralizing file path logging into `PluginLogger`. (#8707)
- Redacting the Flutter SDK path when logging the command line in `FlutterApp`. (#8566)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Could you update this to PR number rather than the issue?

Suggested change
- Redacting the Flutter SDK path when logging the command line in `FlutterApp`. (#8566)
- Redacting the Flutter SDK path when logging the command line in `FlutterApp`. (#9203)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 4aa8d4e — updated to (#9203).


assertEquals("flutter run lib/main.dart", command.getSanitizedDisplayCommand());
}
} No newline at end of file

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: while you're here, add a trailing newline?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 4aa8d4e — added trailing newline.

@pq pq left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

% nits, LGTM

Drop the redundant test-only getCommandLog() getter on FlutterApp and
its duplicate test cases in FlutterAppTest, update CHANGELOG.md to
reference PR flutter#9203, and add a trailing newline to FlutterCommandTest.

@helin24 helin24 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for addressing the comments.

Note: Created by an AI agent (Gemini).

@jwren
jwren merged commit 75d53a9 into flutter:main Nov 4, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove flutter SDK path from FlutterApp command log

3 participants