Skip to content
This repository was archived by the owner on Sep 2, 2022. It is now read-only.

Commit 97e0e9e

Browse files
author
Alexander Zuev
committed
8268775: Password is being converted to String in AccessibleJPasswordField
Reviewed-by: prr
1 parent 1c18f91 commit 97e0e9e

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

src/java.desktop/share/classes/javax/swing/JPasswordField.java

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -510,20 +510,19 @@ private String getEchoString(String str) {
510510
* @since 1.6
511511
*/
512512
public String getAtIndex(int part, int index) {
513-
String str = null;
514513
if (part == AccessibleText.CHARACTER) {
515-
str = super.getAtIndex(part, index);
514+
return getEchoString(super.getAtIndex(part, index));
516515
} else {
517516
// Treat the text displayed in the JPasswordField
518517
// as one word and sentence.
519-
char[] password = getPassword();
520-
if (password == null ||
521-
index < 0 || index >= password.length) {
518+
int length = getDocument().getLength();
519+
if (index < 0 || index >= length) {
522520
return null;
523521
}
524-
str = new String(password);
522+
char[] password = new char[length];
523+
Arrays.fill(password, getEchoChar());
524+
return new String(password);
525525
}
526-
return getEchoString(str);
527526
}
528527

529528
/**
@@ -544,8 +543,7 @@ public String getAtIndex(int part, int index) {
544543
*/
545544
public String getAfterIndex(int part, int index) {
546545
if (part == AccessibleText.CHARACTER) {
547-
String str = super.getAfterIndex(part, index);
548-
return getEchoString(str);
546+
return getEchoString(super.getAfterIndex(part, index));
549547
} else {
550548
// There is no word or sentence after the text
551549
// displayed in the JPasswordField.
@@ -571,8 +569,7 @@ public String getAfterIndex(int part, int index) {
571569
*/
572570
public String getBeforeIndex(int part, int index) {
573571
if (part == AccessibleText.CHARACTER) {
574-
String str = super.getBeforeIndex(part, index);
575-
return getEchoString(str);
572+
return getEchoString(super.getBeforeIndex(part, index));
576573
} else {
577574
// There is no word or sentence before the text
578575
// displayed in the JPasswordField.
@@ -627,14 +624,14 @@ public AccessibleTextSequence getTextSequenceAt(int part, int index) {
627624
} else {
628625
// Treat the text displayed in the JPasswordField
629626
// as one word, sentence, line and attribute run
630-
char[] password = getPassword();
631-
if (password == null ||
632-
index < 0 || index >= password.length) {
627+
int length = getDocument().getLength();
628+
if (index < 0 || index >= length) {
633629
return null;
634630
}
631+
char[] password = new char[length];
632+
Arrays.fill(password, getEchoChar());
635633
String text = new String(password);
636-
return new AccessibleTextSequence(0, password.length - 1,
637-
getEchoString(text));
634+
return new AccessibleTextSequence(0, password.length - 1, text);
638635
}
639636
}
640637

0 commit comments

Comments
 (0)