RFR: 8374329: PasswordField ignores custom accessible text

Andy Goryachev angorya at openjdk.org
Wed Dec 24 16:18:27 UTC 2025


On Wed, 24 Dec 2025 09:01:49 GMT, Christopher Schnick <duke at openjdk.org> wrote:

> This is a pretty simple fix for the accessible text of password fields.

Would it be possible to add a unit test to `PasswordFieldTest`, with all four combinations of `promptText` and `accessibleText`?

Also, I think we should add an explicit check (perhaps as a part of the above test case) that the password value does not leak?

Something like

pwdField.setText("pw");
// all nulls
assertEquals(null, pwdField.queryAccessibleAttribute(AccessibleAttribute.TEXT));
// accessibleText
pwdField.setAccessibleText("1");
assertEquals("1", pwdField.queryAccessibleAttribute(AccessibleAttribute.TEXT));
// both
pwdField.setPromptText("2");
assertEquals("1", pwdField.queryAccessibleAttribute(AccessibleAttribute.TEXT));
// prompt text
pwdField.setAccessibleText(null);
assertEquals("2", pwdField.queryAccessibleAttribute(AccessibleAttribute.TEXT));
// back to nulls
pwdField.setPromptText(null);
assertEquals(null, pwdField.queryAccessibleAttribute(AccessibleAttribute.TEXT));


code above was not compiled, just a suggestion

modules/javafx.controls/src/main/java/javafx/scene/control/PasswordField.java line 85:

> 83:             case TEXT:
> 84:                 String accText = getAccessibleText();
> 85:                 if (accText != null && !accText.isEmpty()) return accText;

minor: please add { }'s

modules/javafx.controls/src/main/java/javafx/scene/control/PasswordField.java line 86:

> 84:                 String accText = getAccessibleText();
> 85:                 if (accText != null && !accText.isEmpty()) return accText;
> 86:                 return getPromptText();

`getPromptText()` returns "" when `promptText` property is not set, resulting in this method returning "".  Shouldn't it return `null` instead?

-------------

PR Review: https://git.openjdk.org/jfx/pull/2020#pullrequestreview-3611297624
PR Review Comment: https://git.openjdk.org/jfx/pull/2020#discussion_r2645983478
PR Review Comment: https://git.openjdk.org/jfx/pull/2020#discussion_r2645982535


More information about the openjfx-dev mailing list