JDK-4238266 : StringTokenizer.hasMoreElements() has unexpected side-effect
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util
  • Affected Version: 1.2.2
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: solaris_2.5
  • CPU: sparc
  • Submitted: 1999-05-14
  • Updated: 1999-10-26
  • Resolved: 1999-09-04
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
1.3.0 kestrelFixed
Related Reports
Relates :  
Description

Name: mgC56079			Date: 05/14/99



 StringTokenizer.hasMoreElements() and StringTokenizer.hasMoreTokens() methods
 have unexpected side-effect - object's internal state is changed after calling these
 methods which is not reflected in the specification:

------------------------------------------------------
      Tests if there are more tokens available from this tokenizer's string. 
      If this method returns true, then a subsequent call to
      nextToken with no argument will successfully return a token.
------------------------------------------------------

 Following example demonstrates that the internal state of the object has been changed while 
 calling hasMoreTokens()

--------------Test.java
import java.util.*;

public class Test {  
  public static void main(String[] argv) {
    StringTokenizer st1 = new StringTokenizer("ab", "b");
    System.out.println(st1.nextToken());
    System.out.println(st1.nextToken(""));

    StringTokenizer st2 = new StringTokenizer("ab", "b");
    System.out.println(st2.nextToken());
    st2.hasMoreTokens();
    System.out.println(st2.nextToken(""));

  }
}
--------------Output
a
b
a
java.util.NoSuchElementException
        at java.util.StringTokenizer.nextToken(StringTokenizer.java)
        at java.util.StringTokenizer.nextToken(StringTokenizer.java)
        at Test.main(Test.java:12)
--------------
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: kestrel FIXED IN: kestrel INTEGRATED IN: kestrel VERIFIED IN: kestrel
14-06-2004

EVALUATION Will fix fo Kestrel FCS naveen.sanjeeva@eng 1999-09-03
03-09-1999