@@ -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