JDK-4256661 : TextComponent.AccessibleAWTTextComponent.getBeforeIndex(...) works incorrectly.
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.3.0,5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: generic,solaris_2.5.1
  • CPU: generic,sparc
  • Submitted: 1999-07-23
  • Updated: 2004-09-01
  • Resolved: 2003-10-23
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
5.0 b26Fixed
Related Reports
Relates :  
Description

Name: aaC67449			Date: 07/23/99



TextComponent.AccessibleAWTTextComponent.getBeforeIndex(int part, int index) 
works incorrectly, when 'part' parameter is AccessibleText.WORD.
It returns a space (" ") instead of the correct word.

See example.
------------- example --------------
import java.awt.*;
import javax.accessibility.*;

public class Test {

   public static void main(String argv[]) {

       TextField o=new TextField("Test1 test2.");
       AccessibleText c = o.getAccessibleContext().getAccessibleText(); 
       if (!c.getBeforeIndex(AccessibleText.WORD,7).equals("Test1")) {
           System.out.println("Failed. Method returns:\""
                   +c.getBeforeIndex(AccessibleText.WORD,7)+"\"");
       } else { 
	   System.out.println("Passed");
       }	  
   }  

}

------------- JDK1.3L output ---------------
Warning: JIT compiler "sunwjit" not found. Will use interpreter.
Failed. Method returns:" "

======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: tiger tiger-beta FIXED IN: tiger tiger-beta INTEGRATED IN: tiger-b26 tiger-beta VERIFIED IN: tiger-b63
13-09-2004

EVALUATION Commit to fix in ladybird. eric.hawkes@eng 1999-09-01 ========================================================================== I believe this is unimplemented functionality. We have been told not to continue working on it, so probably will not fix. eric.hawkes@eng 2001-07-23 Name: rpR10076 Date: 10/08/2003 Incorrect usage of java.text.BreakIterator when it is a word iterator. Not everything between two consecutive word delimiters is a word, and our code was not prepared to that. ###@###.### ======================================================================
13-09-2004

SUGGESTED FIX Name: rpR10076 Date: 10/08/2003 ------- TextComponent.java ------- *** /tmp/sccs._6aqR2 Wed Oct 8 18:08:29 2003 --- TextComponent.java Wed Oct 8 18:08:24 2003 *************** *** 1040,1046 **** --- 1045,1082 ---- } } + private static final boolean NEXT = true; + private static final boolean PREVIOUS = false; + /** + * Needed to unify forward and backward searching. + * The method assumes that s is the text assigned to words. + */ + private int findWordLimit(int index, BreakIterator words, boolean direction, + String s) { + // Fix for 4256660 and 4256661. + // Words iterator is different from character and sentence iterators + // in that end of one word is not necessarily start of another word. + // Please see java.text.BreakIterator JavaDoc. The code below is + // based on nextWordStartAfter example from BreakIterator.java. + int last = (direction == NEXT) ? words.following(index) + : words.preceding(index); + int current = (direction == NEXT) ? words.next() + : words.previous(); + while (current != BreakIterator.DONE) { + for (int p = Math.min(last, current); p < Math.max(last, current); p++) { + if (Character.isLetter(s.charAt(p))) { + return last; + } + } + last = current; + current = (direction == NEXT) ? words.next() + : words.previous(); + } + return BreakIterator.DONE; + } + + /** * Returns the String after a given index. * * @param part the AccessibleText.CHARACTER, AccessibleText.WORD, *************** *** 1063,1069 **** String s = TextComponent.this.getText(); BreakIterator words = BreakIterator.getWordInstance(); words.setText(s); ! int start = words.following(index); if (start == BreakIterator.DONE || start >= s.length()) { return null; } --- 1099,1105 ---- String s = TextComponent.this.getText(); BreakIterator words = BreakIterator.getWordInstance(); words.setText(s); ! int start = findWordLimit(index, words, NEXT, s); if (start == BreakIterator.DONE || start >= s.length()) { return null; } *************** *** 1116,1124 **** String s = TextComponent.this.getText(); BreakIterator words = BreakIterator.getWordInstance(); words.setText(s); ! int end = words.following(index); ! end = words.previous(); ! int start = words.previous(); if (start == BreakIterator.DONE) { return null; } --- 1152,1162 ---- String s = TextComponent.this.getText(); BreakIterator words = BreakIterator.getWordInstance(); words.setText(s); ! int end = findWordLimit(index, words, PREVIOUS, s); ! if (end == BreakIterator.DONE) { ! return null; ! } ! int start = words.preceding(end); if (start == BreakIterator.DONE) { return null; } ======================================================================
13-09-2004