Skip to content

Conversation

naotoj
Copy link
Member

@naotoj naotoj commented Aug 27, 2025

Providing a couple of utility methods using the "built-in" Console implementation to support tools that require password input, such as keytool, ensuring they work even when std0ut is redirected.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8366261: Provide utility methods for sun.security.util.Password (Enhancement - P4)

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/26973/head:pull/26973
$ git checkout pull/26973

Update a local copy of the PR:
$ git checkout pull/26973
$ git pull https://git.openjdk.org/jdk.git pull/26973/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 26973

View PR using the GUI difftool:
$ git pr show -t 26973

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/26973.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Aug 27, 2025

👋 Welcome back naoto! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Aug 27, 2025

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk
Copy link

openjdk bot commented Aug 27, 2025

@naotoj The following labels will be automatically applied to this pull request:

  • core-libs
  • security

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing lists. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added security security-dev@openjdk.org core-libs core-libs-dev@openjdk.org rfr Pull request is ready for review labels Aug 27, 2025
@mlbridge
Copy link

mlbridge bot commented Aug 27, 2025

Webrevs

private static final boolean istty = istty();
static final int TTY_STDIN_MASK = 0x00000001;
static final int TTY_STDOUT_MASK = 0x00000002;
static final int TTY_STDERR_MASK = 0x00000004;
Copy link
Member

Choose a reason for hiding this comment

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

I recommend marking these fields as @Native.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point. Fixed

public static Optional<JdkConsoleImpl> passwordConsole() {
return INSTANCE.orElseSet(() -> {
// If there's already a proper console, throw an exception
if (System.console() != null) {
Copy link
Member

Choose a reason for hiding this comment

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

Since this initializes the console, this means the console can only be available when there is no provider and stdin is tty, but stdout is not. Is this intended? (In other words, should we make System.console() lazy, as it is initialized with java.io.Console as Console.cons?)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, this is intentional. This entry is dedicated solely to Password, and it is expected that System.console() will be called beforehand so that normal cases (without redirection) are handled by System.console(). The null check is a safeguard to prevent future Password refactoring from invoking this method without first calling System.console() in the standard case.

Copy link
Member

@stuart-marks stuart-marks Aug 30, 2025

Choose a reason for hiding this comment

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

It would be good to add comments that describes this precondition. We've all been discussing it so we "know" what it's doing and why. But other readers, like @liach, and future maintainers of the Password class, will know what the requirements are. (EDIT: I meant "will need to know" but I think you understood.)

Copy link
Member Author

Choose a reason for hiding this comment

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

It would be good to add comments that describes this precondition.

Good point. Explained it in its comment.

Co-authored-by: Francesco Andreuzzi <andreuzzi.francesco@gmail.com>
@@ -21,7 +21,7 @@
* questions.
*/

/**
/*
* @test
* @bug 8295803 8299689 8351435 8361613
Copy link
Member

Choose a reason for hiding this comment

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

Should 8366261 be included?

new JdkConsoleImpl(
Charset.forName(StaticProperty.stdinEncoding(), UTF_8.INSTANCE),
Charset.forName(StaticProperty.stdoutEncoding(), UTF_8.INSTANCE))) :
Optional.empty();
Copy link
Member

@stuart-marks stuart-marks Sep 4, 2025

Choose a reason for hiding this comment

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

(Finally getting back to this.)

The code returns an Optional containing a JdkConsoleImpl instance, or an empty Optional. However the comment above says it returns a JdkConsoleImpl instance or null. Which do we want it to be? Either is OK, but the comment should agree with the code.

I think @wangweij might want to weigh in here since his code will be calling this.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, yes. Comment does not align with the code. I am fine either way too.

Copy link
Contributor

@wangweij wangweij Sep 6, 2025

Choose a reason for hiding this comment

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

Either is OK. Optional sounds more modern and forces me to consider the empty case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core-libs core-libs-dev@openjdk.org rfr Pull request is ready for review security security-dev@openjdk.org
Development

Successfully merging this pull request may close these issues.

6 participants