JDK-4404519 : (spec thread) Thread.setDaemon() should not be allowed after the thread terminates
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 1.3.0
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2001-01-13
  • Updated: 2007-07-09
  • Resolved: 2011-05-18
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.
JDK 7 Other
7 b16Fixed OpenJDK6Fixed
Related Reports
Relates :  
Description
Name: boT120536			Date: 01/12/2001


java version "1.3.0_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0_01)
Java HotSpot(TM) Client VM (build 1.3.0_01, mixed mode)

The specification for Thread.setDaemon says:

"This method must be called before the thread is started. "

However the implementation uses isAlive() to determine whether or not the
thread has been started. This means that when the thread has terminated isAlive
() returns false and setDaemon is allowed to proceed *after* the thread has
started. Obviously this has no practical consequences - except in pedantic
compliance tests.

This is very minor but should be fixed as part of the general thread tidy up
alluded to in various bug evaluations. The simplest fix is probably to the
specification.
(Review ID: 115025) 
======================================================================

Comments
SUGGESTED FIX ------- Thread.java ------- 1235,1252c1235,1249 < * Marks this thread as either a daemon thread or a user thread. The < * Java Virtual Machine exits when the only threads running are all < * daemon threads. < * <p> < * This method must be called before the thread is started. < * <p> < * This method first calls the <code>checkAccess</code> method < * of this thread < * with no arguments. This may result in throwing a < * <code>SecurityException </code>(in the current thread). < * < * @param on if <code>true</code>, marks this thread as a < * daemon thread. < * @exception IllegalThreadStateException if this thread is active. < * @exception SecurityException if the current thread cannot modify < * this thread. < * @see #isDaemon() < * @see #checkAccess --- > * Marks this thread as either a {@linkplain #isDaemon daemon} thread > * or a user thread. The Java Virtual Machine exits when the only > * threads running are all daemon threads. > * > * <p> This method must be invoked before the thread is started. > * > * @param on > * if {@code true}, marks this thread as a daemon thread > * > * @throws IllegalThreadStateException > * if this thread is {@linkplain #isAlive alive} > * > * @throws SecurityException > * if {@link #checkAccess} determines that the current > * thread cannot modify this thread
25-06-2007

EVALUATION This change eliminates the notion of an "active thread" which was never defined and serves no purpose. In the case of setDaemon the term "alive" is substituted.
08-05-2007

SUGGESTED FIX http://javaweb/java/jdk/ws/libs/rev/4404519 Might need fasttrack CCC, but seems to be a simple clarification.
08-05-2007

EVALUATION Changing the spec slightly to say this is allowed behavior seems the best solution.
25-10-2005

WORK AROUND Name: boT120536 Date: 01/12/2001 N/A ======================================================================
11-06-2004