-
Bug
-
Resolution: Fixed
-
P2
-
1.4.0
-
beta2
-
sparc
-
solaris_2.6
-
Verified
Name: dfR10049 Date: 01/04/2001
The new behavior of java.text.CollationElementIterator.setOffset() is incorrect.
If string is consist of one character setOffset(0) will set offset to 0
and previous() will return NULLORDER. After adding one more character to the string
setOffset(0) will set offset to 1, and previous() will not return NULLORDER.
In the previous jdk releases previous() will return NULLORDER in this case.
Javadoc states:
public void setOffset(int newOffset)
Sets the iterator to point to the collation element corresponding to the
specified character (the parameter is a CHARACTER offset in the
original string, not an offset into its corresponding sequence of collation
elements). The value returned by the next call to next() will be the
collation element corresponding to the specified position in the text. If that
position is in the middle of a contracting character sequence, the result of
the next call to next() is the collation element for that sequence. This
means that getOffset() is not guaranteed to return the same value as was
passed to a preceding call to setOffset().
But if rule is "< a, A < d; D" the string "aD" has no contracting character sequences
and setOffset(0) should set offset to 0.
Please see an example demonstrating the bug below:
----------- Test.java ----------------
import java.text.*;
public class Test {
public static void main(String args[]) {
try {
String rule = "< a, A < d; D";
System.out.println("rule: " + rule);
System.out.println("========================");
RuleBasedCollator rbc = new RuleBasedCollator(rule);
String str = "aD";
CollationElementIterator iterator =
rbc.getCollationElementIterator(str);
iterator.setOffset(0);
int offset = iterator.getOffset();
int prev = iterator.previous();
iterator.setOffset(0);
int next = iterator.next();
System.out.println("text: " + str);
System.out.println("offset: " + offset);
System.out.println("prev: " + prev);
System.out.println("next: " + next);
System.out.println("========================");
str = "a";
iterator = rbc.getCollationElementIterator(str);
iterator.setOffset(0);
offset = iterator.getOffset();
prev = iterator.previous();
iterator.setOffset(0);
next = iterator.next();
System.out.println("text: " + str);
System.out.println("offset: " + offset);
System.out.println("prev: " + prev);
System.out.println("next: " + next);
} catch (ParseException e) {
System.out.println("Unexpected ParseException: " + e);
}
}
}
#----------------- output from the test ----------------------
#> java -version
java version "1.4.0-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta-b46)
Java HotSpot(TM) Client VM (build 1.4beta-B45, mixed mode)
#> java Test
rule: < a, A < d; D
========================
text: aD
offset: 1
prev: 65536
next: 65536
========================
text: a
offset: 0
prev: -1
next: 65536
-------------------------
#> java -version
java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, interpreted mode)
#> java Test
rule: < a, A < d; D
========================
text: aD
offset: 0
prev: -1
next: 65536
========================
text: a
offset: 0
prev: -1
next: 65536
======================================================================