Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4338282
Votes 0
Synopsis StringTokenizer behavior different in latest JDK1.3
Category java:classes_util
Reported Against 1.3
Release Fixed
State 11-Closed, Not a Defect, bug
Priority: 3-Medium
Related Bugs 4238266 , 4842812
Submit Date 15-MAY-2000
Description
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.  




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) 
======================================================================
Work Around




Post processing the string to check for the previous delimiter.
======================================================================
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.  

 xxxxx@xxxxx  2000-05-22
Comments
  
  Include a link with my name & email   

Submitted On 14-JUN-2000
posicks
How is this not a bug?!  It changes the base functionality of the class without documenting that it was 
done, in the enhancements documentation.  This class should work exactly as it always has


Submitted On 23-JUN-2000
carljo
I agree that this is a bug, but in my case, I got around the problem by creating the tokenizer with
returnTokens set to true and explicitly skipping the tokens.  This provided the desired results.

Sample code

               StringTokenizer tokens=new StringTokenizer(fileLogValue,&quot;,&quot;, true);
                String newLogClassName = tokens.nextToken(&quot;,&quot;).trim();
                String ignore=tokens.nextToken(&quot;,&quot;);
                String newLogLevel = tokens.nextToken(&quot;,&quot;).trim();
                ignore=tokens.nextToken(&quot;,&quot;);
                String newLogAddress = tokens.nextToken(&quot;&quot;).trim(); // change of token
                /* the last nextToken was returning the previous comma */
                /* using the above method, skips the comma */


Submitted On 21-JUL-2000
aholland
This is a bug and it should be fixed. It is a serious incompatibility with previous Java 2 JDK's and JDK 1.x 
JDK's.


Submitted On 26-JUL-2000
seguret
Of course it's a bug !
I cannot anderstand how it could go through the non-regression tests.
It prevented us to use the JDK1.3 until we suppressed all access to this class.


Submitted On 21-AUG-2000
rowls
Sure looks like a bug to me. I could certainly break alot of
peoples code.


Submitted On 24-AUG-2000
tormod
It sure breaks a lot of code, including third-party java 
code, which we have no control over.

For example the excellent servlet engine JRun 2.x. The 
handling of cookies here is obviously dependent on a 
StringTokenizer, and when JRun is used with JDK 1.3, all 
cookie values are returned with &quot;=&quot;+&lt;real value&gt;, an equal 
sign is added in front of every cookie value. 

That means a LOT of servlets must be changed...

If this is not a bug, bite me!


Submitted On 11-OCT-2000
pfditmars
What comments is the &quot;evaluation&quot; referring to?  Nowhere does anyone attempt to explain how this is &quot;Not a  
bug&quot;.  If changing the behavior was intentional, it should have been documented and an alternative 
constructor should have been introduced to obtain the new behavior.  Changing the behavior without doing 
so is a bug.  I can work around it in my code, but I can't easily work around it in class libraries that I 
depend on.  If the dates on this bug report are correct, the bug was reported early and closed a week later!  
The s**t is going to start hitting the fan as people try to pick up JDK1.3 and really using it (supposedly now 
that the bugs have been worked out in beta!).


Submitted On 14-NOV-2000
ttwang
4338282 and 4238266 are mirror opposites.  Recommend rolling
back fix 4238266, which would resolve the very real
incompatibility issue.  Need to rollback the JCK test case
too.

 -Thomas Wang


Submitted On 08-OCT-2001
joeterbeck
i'm sorry; this is definately a bug;
it makes nearly all of my usage of StringTokenizer heretofore
totally obsolete and in need of rewriting;


Submitted On 16-JAN-2002
lizardpie
This is definitely a bug.  I spent a lot of time trying to 
figure out why our code stopped working when running 
1.3.1.  You should have documented this and provided an 
alternate contructor.  I have lots of code to fix now!!


Submitted On 25-MAR-2003
smiths
This one never bothered me - I never change my delmiter.


Submitted On 18-AUG-2005
lordismyshepherd
Workaround: Post processing the string to check for the previous delimiter.

Please tell me there is a method to get the previous delimiter in StringTokenizer class...  



PLEASE NOTE: JDK6 is formerly known as Project Mustang