JDK-4338282 : StringTokenizer behavior different in latest JDK1.3
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util
  • Affected Version: 1.3.0
  • Priority: P3
  • Status: Closed
  • Resolution: Not an Issue
  • OS: windows_nt
  • CPU: x86
  • Submitted: 2000-05-15
  • Updated: 2000-05-22
  • Resolved: 2000-05-22
Related Reports
Relates :  
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