Print this page


Split Close
Expand all
Collapse all
          --- old/test/java/lang/Thread/StopBeforeStart.java
          +++ new/test/java/lang/Thread/StopBeforeStart.java
↓ open down ↓ 15 lines elided ↑ open up ↑
  16   16   * 2 along with this work; if not, write to the Free Software Foundation,
  17   17   * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18   18   *
  19   19   * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20   20   * or visit www.oracle.com if you need additional information or have any
  21   21   * questions.
  22   22   */
  23   23  
  24   24  /*
  25   25   * @test
  26      - * @bug     4519200
       26 + * @bug     4519200 6562203
  27   27   * @summary Confirm a Thread.stop before start complies with the spec
  28   28   * @author  Pete Soper
  29   29   *
  30   30   * Confirm that a thread that had its stop method invoked before start
  31      - * does properly terminate with expected exception behavior. NOTE that
  32      - * arbitrary application threads could return from their run methods faster
  33      - * than the VM can throw an async exception.
       31 + * does properly terminate with expected exception behavior.
  34   32   */
  35   33  public class StopBeforeStart {
  36   34  
  37   35      private static final int JOIN_TIMEOUT=10000;
  38   36  
  39      -    private class MyThrowable extends Throwable {
  40      -    }
       37 +    @SuppressWarnings("serial")
       38 +    private class MyThrowable extends Throwable { }
  41   39  
  42   40      private class Catcher implements Thread.UncaughtExceptionHandler {
  43      -        private boolean nullaryStop;
       41 +        private final boolean nullaryStop;
  44   42          private Throwable theThrowable;
  45   43          private Throwable expectedThrowable;
  46   44          private boolean exceptionThrown;
  47   45  
  48   46          Catcher(boolean nullaryStop) {
  49   47              this.nullaryStop = nullaryStop;
  50   48              if (!nullaryStop) {
  51   49                  expectedThrowable = new MyThrowable();
  52   50              }
  53   51          }
↓ open down ↓ 49 lines elided ↑ open up ↑
 103  101          runit(true, new MyThread(),"Runnable");
 104  102      }
 105  103  
 106  104      private void runit(boolean nullaryStop, Thread thread,
 107  105                          String type) throws Throwable {
 108  106  
 109  107          Catcher c = new Catcher(nullaryStop);
 110  108          thread.setUncaughtExceptionHandler(c);
 111  109  
 112  110          if (nullaryStop) {
 113      -            thread.stop();
      111 +            stop(thread);
 114  112          } else {
 115      -            thread.stop(c.expectedThrowable);
      113 +            stop(thread, c.expectedThrowable);
 116  114          }
 117  115  
 118  116          thread.start();
 119  117          thread.join(JOIN_TIMEOUT);
 120  118  
 121  119          if (thread.getState() != Thread.State.TERMINATED) {
 122  120  
 123      -            thread.stop();
      121 +            stop(thread);
 124  122  
 125  123              // Under high load this could be a false positive
 126  124              throw new RuntimeException(type +
 127  125                          " test:" + " app thread did not terminate");
 128  126          }
 129  127  
 130  128          c.check(type);
 131  129      }
      130 +
      131 +    @SuppressWarnings("deprecation")
      132 +    void stop(Thread thread) {
      133 +        thread.stop();
      134 +    }
      135 +
      136 +    @SuppressWarnings("deprecation")
      137 +    void stop(Thread thread, Throwable t) {
      138 +        thread.stop(t);
      139 +    }
 132  140  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX