Skip to content

Read the password to encrypt from the standard input when there is no console (fix #10230) - #13589

Merged
cstamas merged 1 commit into
apache:maven-3.10.xfrom
arturobernalg:fix/maven-10230-encrypt-redirected-3.10
Oct 20, 2026
Merged

cstamas merged 1 commit into
apache:maven-3.10.xfrom
arturobernalg:fix/maven-10230-encrypt-redirected-3.10

Conversation

@arturobernalg

Copy link
Copy Markdown
Member

What and why

mvn --encrypt-master-password and mvn --encrypt-password read the password with System.console(). When the streams are redirected there is no console, the password stayed null, and the command printed an empty {}, which makes it unusable from another program (#10230, MNG-8398). I could reproduce it on 3.9.16: echo myMasterPassword | mvn --encrypt-master-password prints {}.

How

A new MavenCli.readPassword reads the password from the console and, when there is none, from the first line of the standard input. When no password can be read, or it is empty, the command now fails with No password was provided instead of encrypting nothing. The standard input is not closed.

This is for 3.10.x. Maven 4 does not have these options any more, it has mvnenc.

Tests

MavenCliTest covers reading from a redirected input and the missing and empty cases. The console path cannot be mocked, because java.io.Console is final. I also built the distribution of this branch: echo myMasterPassword | mvn --encrypt-master-password prints the encrypted {...} value, and with an empty input it fails with the new message. maven-embedder and its dependencies pass (45 tests) and spotless is clean. I did not run the integration tests.


To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
check one of the following:

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

Two minor style and documentation issues in the new readPassword helper.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

@arturobernalg
arturobernalg force-pushed the fix/maven-10230-encrypt-redirected-3.10 branch from 47935ec to 76af3a4 Compare October 17, 2026 09:09
@arturobernalg

Copy link
Copy Markdown
Member Author

Both points addressed in 76af3a4. The Javadoc of readPassword now has @param, @return and @throws tags, and says that the prompt is not shown when the password is read from the input. I left it unshown on purpose: that case is a non-interactive caller, for example echo secret | mvn --encrypt-master-password, and a prompt would only add noise to its output.

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

Clean refactoring that correctly extracts the duplicated password-reading logic into a single readPassword method. The fail-fast behavior on missing passwords is a strict improvement over the old silent-empty-output behavior.

One remaining nit: Charset.defaultCharset() for stdin decoding.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

… console (fix apache#10230)

With redirected streams System.console() is null, the password stayed null and --encrypt-master-password and --encrypt-password printed an empty {}. The password is now read from the first line of the standard input, and the command fails when there is none instead of encrypting nothing.
@arturobernalg
arturobernalg force-pushed the fix/maven-10230-encrypt-redirected-3.10 branch from 76af3a4 to 09a406b Compare October 17, 2026 10:19
@arturobernalg

Copy link
Copy Markdown
Member Author

Switched the decoding of the redirected input to UTF-8 in 09a406b, so it no longer depends on the locale, and added a test with non-ASCII characters (MavenCliTest#testReadPasswordFromRedirectedInputIsDecodedAsUtf8). MavenCliTest passes.

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

Previous findings are all addressed. LGTM.

  • Javadoc ✅ — @param, @return, @throws IOException, and @throws IllegalStateException all present and accurate. The note that prompt is silently skipped in the non-interactive path is documented correctly.
  • StandardCharsets.UTF_8 ✅ — InputStreamReader now hardcodes UTF-8; the locale-dependent Charset.defaultCharset() issue is gone.
  • Test coverage ✅ — three tests cover redirected-input read, UTF-8 decode, and empty/blank rejection. Pre-fix validation: testReadPasswordRejectsMissingPassword and testReadPasswordFromRedirectedInput target the exact IllegalStateException and BufferedReader.readLine() paths introduced by the fix — both were failing before (old code returned null silently instead of throwing).

This review was generated by an AI agent, Hermès on behalf of @gnodet.

@gnodet gnodet added this to the 3.10.1 milestone Oct 19, 2026
@cstamas cstamas added the bug Something isn't working label Oct 20, 2026
@cstamas
cstamas merged commit 73e6521 into apache:maven-3.10.x Oct 20, 2026
14 checks passed
slachiewicz pushed a commit that referenced this pull request Nov 3, 2026
… console (fix #10230) (#13589)

`mvn --encrypt-master-password` and `mvn --encrypt-password` read the password with `System.console()`. When the streams are redirected there is no console, the password stayed `null`, and the command printed an empty `{}`, which makes it unusable from another program (#10230, MNG-8398). I could reproduce it on 3.9.16: `echo myMasterPassword | mvn --encrypt-master-password` prints `{}`.

A new `MavenCli.readPassword` reads the password from the console and, when there is none, from the first line of the standard input. When no password can be read, or it is empty, the command now fails with `No password was provided` instead of encrypting nothing. The standard input is not closed.

This is for 3.10.x. Maven 4 does not have these options any more, it has `mvnenc`.

`MavenCliTest` covers reading from a redirected input and the missing and empty cases. The console path cannot be mocked, because `java.io.Console` is final. I also built the distribution of this branch: `echo myMasterPassword | mvn --encrypt-master-password` prints the encrypted `{...}` value, and with an empty input it fails with the new message. `maven-embedder` and its dependencies pass (45 tests) and spotless is clean. I did not run the integration tests.

---

To make clear that you license your contribution under
the [Apache License Version 2.0, January 2004](https://www.apache.org/licenses/LICENSE-2.0)
check one of the following:

- [x] I hereby declare this contribution to be licensed under the [Apache License Version 2.0, January 2004](https://www.apache.org/licenses/LICENSE-2.0)
- [x] I hereby declare that I have filed an [Apache Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
slachiewicz pushed a commit to slachiewicz/maven that referenced this pull request Nov 4, 2026
… console (fix apache#10230) (apache#13589)

## What and why

`mvn --encrypt-master-password` and `mvn --encrypt-password` read the password with `System.console()`. When the streams are redirected there is no console, the password stayed `null`, and the command printed an empty `{}`, which makes it unusable from another program (apache#10230, MNG-8398). I could reproduce it on 3.9.16: `echo myMasterPassword | mvn --encrypt-master-password` prints `{}`.

## How

A new `MavenCli.readPassword` reads the password from the console and, when there is none, from the first line of the standard input. When no password can be read, or it is empty, the command now fails with `No password was provided` instead of encrypting nothing. The standard input is not closed.

This is for 3.10.x. Maven 4 does not have these options any more, it has `mvnenc`.

## Tests

`MavenCliTest` covers reading from a redirected input and the missing and empty cases. The console path cannot be mocked, because `java.io.Console` is final. I also built the distribution of this branch: `echo myMasterPassword | mvn --encrypt-master-password` prints the encrypted `{...}` value, and with an empty input it fails with the new message. `maven-embedder` and its dependencies pass (45 tests) and spotless is clean. I did not run the integration tests.

---

To make clear that you license your contribution under
the [Apache License Version 2.0, January 2004](https://www.apache.org/licenses/LICENSE-2.0)
check one of the following:

- [x] I hereby declare this contribution to be licensed under the [Apache License Version 2.0, January 2004](https://www.apache.org/licenses/LICENSE-2.0)
- [x] I hereby declare that I have filed an [Apache Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).

(cherry picked from commit 73e6521)

Ported to Maven 4: only --encrypt-password reads a password here, as
--encrypt-master-password already fails with "not supported anymore";
the code is in compat/maven-embedder. The mvn launcher of Maven 4 does not
have these options; mvnenc is the tool for it.
slachiewicz pushed a commit that referenced this pull request Nov 5, 2026
… console (fix #10230) (#13589)

## What and why

`mvn --encrypt-master-password` and `mvn --encrypt-password` read the password with `System.console()`. When the streams are redirected there is no console, the password stayed `null`, and the command printed an empty `{}`, which makes it unusable from another program (#10230, MNG-8398). I could reproduce it on 3.9.16: `echo myMasterPassword | mvn --encrypt-master-password` prints `{}`.

## How

A new `MavenCli.readPassword` reads the password from the console and, when there is none, from the first line of the standard input. When no password can be read, or it is empty, the command now fails with `No password was provided` instead of encrypting nothing. The standard input is not closed.

This is for 3.10.x. Maven 4 does not have these options any more, it has `mvnenc`.

## Tests

`MavenCliTest` covers reading from a redirected input and the missing and empty cases. The console path cannot be mocked, because `java.io.Console` is final. I also built the distribution of this branch: `echo myMasterPassword | mvn --encrypt-master-password` prints the encrypted `{...}` value, and with an empty input it fails with the new message. `maven-embedder` and its dependencies pass (45 tests) and spotless is clean. I did not run the integration tests.

---

To make clear that you license your contribution under
the [Apache License Version 2.0, January 2004](https://www.apache.org/licenses/LICENSE-2.0)
check one of the following:

- [x] I hereby declare this contribution to be licensed under the [Apache License Version 2.0, January 2004](https://www.apache.org/licenses/LICENSE-2.0)
- [x] I hereby declare that I have filed an [Apache Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).

(cherry picked from commit 73e6521)

Ported to Maven 4: only --encrypt-password reads a password here, as
--encrypt-master-password already fails with "not supported anymore";
the code is in compat/maven-embedder. The mvn launcher of Maven 4 does not
have these options; mvnenc is the tool for it.
slachiewicz pushed a commit that referenced this pull request Nov 5, 2026
… console (fix #10230) (#13589)

## What and why

`mvn --encrypt-master-password` and `mvn --encrypt-password` read the password with `System.console()`. When the streams are redirected there is no console, the password stayed `null`, and the command printed an empty `{}`, which makes it unusable from another program (#10230, MNG-8398). I could reproduce it on 3.9.16: `echo myMasterPassword | mvn --encrypt-master-password` prints `{}`.

## How

A new `MavenCli.readPassword` reads the password from the console and, when there is none, from the first line of the standard input. When no password can be read, or it is empty, the command now fails with `No password was provided` instead of encrypting nothing. The standard input is not closed.

This is for 3.10.x. Maven 4 does not have these options any more, it has `mvnenc`.

## Tests

`MavenCliTest` covers reading from a redirected input and the missing and empty cases. The console path cannot be mocked, because `java.io.Console` is final. I also built the distribution of this branch: `echo myMasterPassword | mvn --encrypt-master-password` prints the encrypted `{...}` value, and with an empty input it fails with the new message. `maven-embedder` and its dependencies pass (45 tests) and spotless is clean. I did not run the integration tests.

---

To make clear that you license your contribution under
the [Apache License Version 2.0, January 2004](https://www.apache.org/licenses/LICENSE-2.0)
check one of the following:

- [x] I hereby declare this contribution to be licensed under the [Apache License Version 2.0, January 2004](https://www.apache.org/licenses/LICENSE-2.0)
- [x] I hereby declare that I have filed an [Apache Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).

(cherry picked from commit 73e6521)

Ported to Maven 4: only --encrypt-password reads a password here, as
--encrypt-master-password already fails with "not supported anymore";
the code is in compat/maven-embedder. The mvn launcher of Maven 4 does not
have these options; mvnenc is the tool for it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants