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

Thread.countStackFrames() does not throw IllegalThreadStateException when thread

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: P4 P4
    • None
    • 1.2.0, 1.2.2
    • hotspot
    • generic, x86, sparc
    • generic, solaris_2.4, windows_nt



      Name: akC45999 Date: 09/29/97



      The specification of Thread.countStackFrames() method require that the target
      thread must be suspended, othrwise, it must throw IllegalThreadStateException.
      But Sun's jdk1.1.4 and jdk1.2M do not throw this exception
      when the thread is not suspended.

      /*------------------------------------------- countStackFrames0102.java
      // test is changed to be run without test harness

      //File: @(#)countStackFrames0102.java 1.1 97/09/26
      //Copyright 09/26/97 Sun Microsystems, Inc. All Rights Reserved

      //package javasoft.sqe.tests.api.java.lang.Thread.countStackFrames0102;

      import java.io.PrintStream;
      //import javasoft.sqe.harness.Status;
      //import javasoft.sqe.harness.Test;

      class Status {

        String msg;
        int res=0;

        public Status(String msg, int res) {
      this.msg=msg;
      this.res=res;
        }

        public static Status passed(String msg) {
      return new Status("passed:"+msg, 0);
        }

        public static Status failed(String msg) {
      return new Status("failed:"+msg, 1);
        }

        public void exit() {
      System.err.println(msg);
      System.exit(res);
        }

      }


      class countStackFrames0102r extends Thread {

        volatile int state=0;

        public void run() {
      state=1;
      try {
      sleep(countStackFrames0102.DELAY);
      } catch (InterruptedException e) {
      }
        }

      }


      public class countStackFrames0102 { //implements Test {

        static final int DELAY=10000; // millisec

        public Status run(String argv[], PrintStream log, PrintStream out) {
      countStackFrames0102r thrd=new countStackFrames0102r();
      thrd.start();
      long time=System.currentTimeMillis();
      while (thrd.state < 1) {
      try {
      Thread.sleep(100);
      } catch (InterruptedException e) {
      }
      if (System.currentTimeMillis()-time>DELAY) {
      return Status.failed("timeout waiting the thread to start");
      }
      }

      int cnt1;
      try {
      cnt1=thrd.countStackFrames();
      if (thrd.isAlive())
      return Status.failed("no IllegalThreadStateException");
      else
      return Status.failed("may be due to thread scheduler");
      } catch (IllegalThreadStateException e) {
      } catch (Throwable t) {
      return Status.failed("wrong exception:"+t.toString());
      } finally {
      thrd.interrupt(); // just to speed up test execution
          }
          return Status.passed("");
        }

        public static void main(String args[]) {
      (new countStackFrames0102()).run(args, System.err, System.out).exit();
        }

      }

      //--------------------------------------- end countStackFrames0102.java
      novo37% javac countStackFrames0102.java
      novo37% setenv CLASSPATH .
      novo37% java countStackFrames0102
      failed:no IllegalThreadStateException




      ======================================================================

            jjb Josh Bloch
            rfqsunw Rfq Rfq (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: