United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-4338282 : StringTokenizer behavior different in latest JDK1.3

Details
Type:
Bug
Submit Date:
2000-05-15
Status:
Closed
Updated Date:
2000-05-22
Project Name:
JDK
Resolved Date:
2000-05-22
Component:
core-libs
OS:
windows_nt
Sub-Component:
java.util
CPU:
x86
Priority:
P3
Resolution:
Not an Issue
Affected Versions:
1.3.0
Fixed Versions:

Related Reports
Relates:

Sub Tasks

Description

Name: skT45625			Date: 05/15/2000


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, mixed mode)

The StringTokenizer class seems to function differently in the latest release
of JDK1.3.  In this new release, changing the delimiter from the initial value
causes the next call to nextToken() to include the previous delimiter.

<pre>

import java.util.*;
class Test
{
  public static void main(String[] args)
  {
    StringTokenizer st = new StringTokenizer("test=abcd efg hij", "=");
    System.out.println(st.nextToken());
    while (st.hasMoreTokens())
    {
      System.out.println(st.nextToken(" "));
    }
  }
}

Output with latest JDK1.3
test
=abcd
efg
hij

Output before lastest JDK1.3
test
abcd
efg
hij

</pre>
(Review ID: 104907) 
======================================================================

                                    

Comments
WORK AROUND



Name: skT45625			Date: 05/15/2000


Post processing the string to check for the previous delimiter.
======================================================================
                                     
2004-06-11
PUBLIC COMMENTS


This is not a bug. The method StringTokenizer.hasMoreElements() had an
unexpected side-effect of consuming the previous delimiters that was not
speced. The fix for bug 4238266 corrected this. So the behavior of the
following code before that fix was,
   StringTokenizer st = new StringTokenizer("ab", "b");
   System.out.println(st.nextToken());
   st.hasMoreElements();
   System.out.println(st.nextToken("");
   

generates,
   a
followed by an exception.
 
would be different form the behavior of,
   StringTokenizer st = new StringTokenizer("ab", "b");
   System.out.println(st.nextToken();
   System.out.println(st.nextToken("");
which generates,
a
b

 
Hence the fix.  
                                     
2004-06-10
EVALUATION


This is not a bug. The method StringTokenizer.hasMoreElements() had an
unexpected side-effect of consuming the previous delimiters that was not
speced. The fix for bug 4238266 corrected this. So the behavior of the
following code before that fix was,
   StringTokenizer st = new StringTokenizer("ab", "b");
   System.out.println(st.nextToken());
   st.hasMoreElements();
   System.out.println(st.nextToken("");
   

generates,
   a
followed by an exception.
 
would be different form the behavior of,
   StringTokenizer st = new StringTokenizer("ab", "b");
   System.out.println(st.nextToken();
   System.out.println(st.nextToken("");
which generates,
a
b

 
Hence the fix.  

XXXX@XXX 2000-05-22
                                     
2000-05-22



Hardware and Software, Engineered to Work Together