@@ -489,20 +489,19 @@ private String getEchoString(String str) {
489489 * @since 1.6
490490 */
491491 public String getAtIndex (int part , int index ) {
492- String str = null ;
493492 if (part == AccessibleText .CHARACTER ) {
494- str = super .getAtIndex (part , index );
493+ return getEchoString ( super .getAtIndex (part , index ) );
495494 } else {
496495 // Treat the text displayed in the JPasswordField
497496 // as one word and sentence.
498- char password [] = getPassword ();
499- if (password == null ||
500- index < 0 || index >= password .length ) {
497+ int length = getDocument ().getLength ();
498+ if (index < 0 || index >= length ) {
501499 return null ;
502500 }
503- str = new String (password );
501+ char [] password = new char [length ];
502+ Arrays .fill (password , getEchoChar ());
503+ return new String (password );
504504 }
505- return getEchoString (str );
506505 }
507506
508507 /**
@@ -523,8 +522,7 @@ public String getAtIndex(int part, int index) {
523522 */
524523 public String getAfterIndex (int part , int index ) {
525524 if (part == AccessibleText .CHARACTER ) {
526- String str = super .getAfterIndex (part , index );
527- return getEchoString (str );
525+ return getEchoString (super .getAfterIndex (part , index ));
528526 } else {
529527 // There is no word or sentence after the text
530528 // displayed in the JPasswordField.
@@ -550,8 +548,7 @@ public String getAfterIndex(int part, int index) {
550548 */
551549 public String getBeforeIndex (int part , int index ) {
552550 if (part == AccessibleText .CHARACTER ) {
553- String str = super .getBeforeIndex (part , index );
554- return getEchoString (str );
551+ return getEchoString (super .getBeforeIndex (part , index ));
555552 } else {
556553 // There is no word or sentence before the text
557554 // displayed in the JPasswordField.
@@ -606,14 +603,14 @@ public AccessibleTextSequence getTextSequenceAt(int part, int index) {
606603 } else {
607604 // Treat the text displayed in the JPasswordField
608605 // as one word, sentence, line and attribute run
609- char password [] = getPassword ();
610- if (password == null ||
611- index < 0 || index >= password .length ) {
606+ int length = getDocument ().getLength ();
607+ if (index < 0 || index >= length ) {
612608 return null ;
613609 }
610+ char [] password = new char [length ];
611+ Arrays .fill (password , getEchoChar ());
614612 String text = new String (password );
615- return new AccessibleTextSequence (0 , password .length - 1 ,
616- getEchoString (text ));
613+ return new AccessibleTextSequence (0 , password .length - 1 , text );
617614 }
618615 }
619616
0 commit comments