Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8360045

StringTokenizer.hasMoreTokens() throws NPE after nextToken(null)

XMLWordPrintable

    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      When StringTokenizer.nextToken(null) is called, it correctly throws a NullPointerException. However, if this exception is caught, a subsequent call to StringTokenizer.hasMoreTokens() on the same instance unexpectedly throws another NullPointerException. This may indicates that the internal state of the StringTokenizer object is corrupted or not properly handled after the initial nextToken(null) call, even when the exception is caught.


      ---------- BEGIN SOURCE ----------
      import java.text.*;
      import java.util.*;


      public class StringTokenizerTest
      {

          public static void main(String[] args) throws ParseException {
              StringTokenizer st = new StringTokenizer("test");
              try {
                  st.nextToken(null);
              } catch (NullPointerException e) {
                  System.out.println("Caught expected exception");
              }
              st.hasMoreTokens(); // throws NullPointerException (BUG)
          }
      }
      ---------- END SOURCE ----------

            naoto Naoto Sato
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated: