db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mike Matrigali <mikem_...@sbcglobal.net>
Subject Re: Question about next() and previous() on CollationElementIterator.
Date Tue, 11 Sep 2007 17:20:38 GMT
My reading of the documentation interface is the same as yours, so your 
results look like a jvm bug.  You may want to add some other simple 
strings and maybe
other locales to see if a specific locale is broken or not.

I hacked my own test to try to mimic the example code in the 
documentation as much as possible and then tried a few variants.  It 
looks like a problem with the locale/test case you picked on sun jvms. 
I tried the program on the ibm15 jvm and got the expected results.  My 
guess is that your eclipse environment is somehow picking up the ibm jvm?

Here is my test program:

import java.text.Collator;
import java.text.RuleBasedCollator;
import java.util.Locale;
import java.text.CollationElementIterator;

public class xxx
{
     public static void tryIt1()
     throws Exception
     {
         String testString = "This is a test";
         RuleBasedCollator ruleBasedCollator =
             (RuleBasedCollator)Collator.getInstance();
         CollationElementIterator collationElementIterator =
             ruleBasedCollator.getCollationElementIterator(testString);
         int primaryOrder =
             CollationElementIterator.primaryOrder(
                     collationElementIterator.next());
         int primaryOrder2 =
             CollationElementIterator.primaryOrder(
                     collationElementIterator.previous());
         System.out.println(
             "next = " + primaryOrder + " \nprevious = " + primaryOrder2);
     }
     public static void tryIt2()
     throws Exception
     {
         String testString = "\uFA2D";
         RuleBasedCollator ruleBasedCollator =
             (RuleBasedCollator)Collator.getInstance();
         CollationElementIterator collationElementIterator =
             ruleBasedCollator.getCollationElementIterator(testString);
         int primaryOrder =
             CollationElementIterator.primaryOrder(
                     collationElementIterator.next());
         int primaryOrder2 =
             CollationElementIterator.primaryOrder(
                     collationElementIterator.previous());
         System.out.println(
             "next = " + primaryOrder + " \nprevious = " + primaryOrder2);
     }
     public static void tryIt3()
     throws Exception
     {
         String testString = "\uFA2D";
         RuleBasedCollator ruleBasedCollator =
             (RuleBasedCollator)Collator.getInstance(new Locale("no","NO"));
         CollationElementIterator collationElementIterator =
             ruleBasedCollator.getCollationElementIterator(testString);
         int primaryOrder =
             CollationElementIterator.primaryOrder(
                     collationElementIterator.next());
         int primaryOrder2 =
             CollationElementIterator.primaryOrder(
                     collationElementIterator.previous());
         System.out.println(
             "next = " + primaryOrder + " \nprevious = " + primaryOrder2);
     }
     public static void tryIt4()
     throws Exception
     {
         String testString = "\uFA2D";
         RuleBasedCollator ruleBasedCollator =
             (RuleBasedCollator)Collator.getInstance(new Locale("no","NO"));
         CollationElementIterator collationElementIterator =
             ruleBasedCollator.getCollationElementIterator(testString);
         int next_order = collationElementIterator.next();
         int previous_order =  collationElementIterator.previous();
         System.out.println(
             "next = " + next_order + " \nprevious = " + previous_order);
     }

     public static void main(String[] args)
     throws Exception
     {
         tryIt1();
         tryIt2();
         tryIt3();
         tryIt4();
     }
}

And my JVM results, all results are on windows XP:

BUG on sun jdk16:
m1_jdk16:5>java -version
java version "1.6.0_01"
Java(TM) SE Runtime Environment (build 1.6.0_01-b06)
Java HotSpot(TM) Client VM (build 1.6.0_01-b06, mixed mode)
m1_jdk16:6>java xxx
next = 102
previous = 102
next = 32767
previous = 64045
next = 32767
previous = 64045
next = 2147418112
previous = -97714176

BUG on sun jdk15:
m1_jdk15:2>java -version
java version "1.5.0_02"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_02-b09)
Java HotSpot(TM) Client VM (build 1.5.0_02-b09, mixed mode)
m1_jdk15:3>export CLASSPATH=".;$CLASSPATH"
m1_jdk15:4>java -version
java version "1.5.0_02"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_02-b09)
Java HotSpot(TM) Client VM (build 1.5.0_02-b09, mixed mode)
m1_jdk15:5>java xxx
next = 102
previous = 102
next = 32767
previous = 64045
next = 32767
previous = 64045
next = 2147418112
previous = -97714176

LOOKS CORRECT ON IBM15
m1_ibm15:37>java -version
java version "1.5.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 
pwi32dev-20061002a (SR3)
)
IBM J9 VM (build 2.3, J2RE 1.5.0 IBM J9 2.3 Windows XP x86-32 
j9vmwi3223-2006100
1 (JIT enabled)
J9VM - 20060915_08260_lHdSMR
JIT  - 20060908_1811_r8
GC   - 20060906_AA)
JCL  - 20061002
m1_ibm15:38>java xxx
next = 102
previous = 102
next = 32767
previous = 32767
next = 32767
previous = 32767
next = 2147418112
previous = 2147418112

Mamta Satoor wrote:
> Hi,
>  
> I have a very simple program(included at the bottom of the mail) which 
> uses the CollationElementIterator to do some very basic next/previous 
> method calls through the iterator. When I run the program, it is not 
> behaving as per the JDBC API documentation at 
> http://java.sun.com/j2se/1.5.0/docs/api/java/text/CollationElementIterator.html#next()

> The JDBC API for next and previous very specifically say that "call 
> next() and then call previous(), or call previous() and then call 
> next()), you'll get back the same element twice." But when I execute the 
> following program with Sun's jdk 1.5 on command line, I get following output
> next is 2147418112
> previous is -97714176
>  
> I had expected the output to be
> next is 2147418112
> previous is 2147418112
>  
> Am I doing something wrong here or not interpreting the documentation 
> correctly? Any help will be greatly appreciated. As a side note, when I 
> run the same program through the Eclipse debugger, I get the expected 
> behavior which is that next and previous both return the same value.
>  
> thanks,
> Mamta
>  
> import java.text.Collator;
> import java.text.RuleBasedCollator;
> import java.util.Locale;
> import java.text.CollationElementIterator;
>  
> public class simpleTest {
>  public static String aa = "\uFA2D";
>  
>  public static void main(String[] args) throws Exception {
>   RuleBasedCollator myCollator = 
> (RuleBasedCollator)Collator.getInstance(new Locale("no","NO"));
>   CollationElementIterator anIterator =  
> myCollator.getCollationElementIterator(aa);
>   System.out.println("next is " + anIterator.next());
>   System.out.println("previous is " + anIterator.previous());
>  }
> }
>  
>  

Mime
View raw message