Skip to content

Commit 5f03341

Browse files
author
Mandy Chung
committedDec 9, 2020
8052260: Reference.isEnqueued() spec does not match the long-standing behavior returning true iff it's in the ref queue
Reviewed-by: kbarrett, alanb
1 parent 6dd06ad commit 5f03341

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed
 

‎src/java.base/share/classes/java/lang/ref/Reference.java

+28-7
Original file line numberDiff line numberDiff line change
@@ -411,14 +411,35 @@ void clearInactiveFinalReference() {
411411
/* -- Queue operations -- */
412412

413413
/**
414-
* Tells whether or not this reference object has been enqueued, either by
415-
* the program or by the garbage collector. If this reference object was
416-
* not registered with a queue when it was created, then this method will
417-
* always return {@code false}.
418-
*
419-
* @return {@code true} if and only if this reference object has
420-
* been enqueued
414+
* Tests if this reference object is in its associated queue, if any.
415+
* This method returns {@code true} only if all of the following conditions
416+
* are met:
417+
* <ul>
418+
* <li>this reference object was registered with a queue when it was created; and
419+
* <li>the garbage collector has added this reference object to the queue
420+
* or {@link #enqueue()} is called; and
421+
* <li>this reference object is not yet removed from the queue.
422+
* </ul>
423+
* Otherwise, this method returns {@code false}.
424+
* This method may return {@code false} if this reference object has been cleared
425+
* but not enqueued due to the race condition.
426+
*
427+
* @deprecated
428+
* This method was originally specified to test if a reference object has
429+
* been cleared and enqueued but was never implemented to do this test.
430+
* This method could be misused due to the inherent race condition
431+
* or without an associated {@code ReferenceQueue}.
432+
* An application relying on this method to release critical resources
433+
* could cause serious performance issue.
434+
* An application should use {@link ReferenceQueue} to reliably determine
435+
* what reference objects that have been enqueued or
436+
* {@link #refersTo(Object) refersTo(null)} to determine if this reference
437+
* object has been cleared.
438+
*
439+
* @return {@code true} if and only if this reference object is
440+
* in its associated queue (if any).
421441
*/
442+
@Deprecated(since="16")
422443
public boolean isEnqueued() {
423444
return (this.queue == ReferenceQueue.ENQUEUED);
424445
}

‎src/java.base/share/classes/jdk/internal/ref/PhantomCleanable.java

+1
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ public void clear() {
160160
*
161161
* @throws UnsupportedOperationException always
162162
*/
163+
@SuppressWarnings("deprecation")
163164
@Override
164165
public final boolean isEnqueued() {
165166
throw new UnsupportedOperationException("isEnqueued");

0 commit comments

Comments
 (0)
Please sign in to comment.