Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6180278

Invalid implementation of AttributedString.getIterator(Attribute[])

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 5.0
    • core-libs
    • None
    • x86
    • windows_xp

      Specification for

      getIterator(AttributedCharacterIterator.Attribute[] attributes)

      states:

      "
      public AttributedCharacterIterator
      getIterator(AttributedCharacterIterator.Attribute[] attributes)

      Creates an AttributedCharacterIterator instance that provides access to
      selected contents of this string. Information about attributes not listed in
      attributes that the implementor may have need not be made accessible through
      the iterator. If the list is null, all available attribute information should
      be made accessible.

      Parameters:
      attributes - a list of attributes that the client is interested in
      Returns:
      an iterator providing access to the text and its attributes
      "

      Please note that specification for AttributedCharacterIterator getIterator()
      states:

      "
      public AttributedCharacterIterator getIterator()

      Creates an AttributedCharacterIterator instance that provides access to the
      entire contents of this string.

      Returns:
      An iterator providing access to the text and its attributes.
      "

      As one can see from example below getIterator(Attribute[]) returns iterator
      that provide access to entire string. But according to specification it should
      provide access to "selected contents of this string". Please do not close this
      bug if selected contents should only mean selected attributes and entrire
      string, instead recategorize bug to specification.

      ******************** test3.java ********************

      import java.text.AttributedCharacterIterator;
      import java.text.AttributedCharacterIterator.Attribute;
      import java.text.AttributedString;
      import java.util.*;


      public class test3 {
          public static void main(String[] args) {
              Attribute[] attributes = {Attribute.LANGUAGE,
                                        Attribute.READING,
                                        Attribute.INPUT_METHOD_SEGMENT};

              Object[] objs = {new Object(), new Object(), new Object()};

              String testString = "long test string";
              int length = testString.length();

              AttributedString as = new AttributedString(testString);
         
              int[] beginIndexes = {1, 2, 3};
              int[] endIndexes = {length - 2, length - 1, 5};
          
              for (int i = 0; i < beginIndexes.length; i++) {
                  as.addAttribute(attributes[i], objs[i], beginIndexes[i],
                                  endIndexes[i]);
              }

              AttributedCharacterIterator iter = as.getIterator(attributes);
          
              int beginIndex = iter.getBeginIndex();
          
              if (beginIndex != 1) {
                  System.out.println("Iterator begin index is " + beginIndex +
                                     " expected 1");
              }
          
              int endIndex = iter.getEndIndex();
          
              if (endIndex != (length - 1)) {
                  System.out.println("Iterator end index is " + endIndex +
                                     " expected " + (length - 1));
              }

              System.out.println("Done");
          }
      }
      ******************** test3.java ********************

      ******************** output ********************

      Z:\bugs\java\tests>Z:\Links\set\jdk-builds\JDK1.5.0b64\windows-i586\bin\
      javac.exe -d . test3.java

      Z:\bugs\java\tests>Z:\Links\set\jdk-builds\JDK1.5.0b64\windows-i586\bin\
      java.exe -version

      java version "1.5.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
      Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode)

      Z:\bugs\java\tests>Z:\Links\set\jdk-builds\JDK1.5.0b64\windows-i586\bin\
      java.exe test3
      Iterator begin index is 0 expected 1
      Iterator end index is 16 expected 15
      Done
      ******************** output ********************
      ###@###.### 10/17/04 13:47 GMT

            nlindenbsunw Norbert Lindenberg (Inactive)
            idergali Ilya Dergalin (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: