JDK-8175797 : (ref) Reference::enqueue method should clear the reference object before enqueuing
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 9
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2017-02-23
  • Updated: 2022-04-28
  • Resolved: 2017-03-09
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 10 JDK 8 JDK 9
10Fixed 8u42Fixed 9 b161Fixed
Related Reports
CSR :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Sub Tasks
JDK-8176389 :  
Soft, weak, and phantom references are automatically-cleared references (see JDK-8071507).   The referent is cleared before the reference object is enqueued.

The `enqueue` method should behave the same and it should clear the reference before enqueuing it to the registered queue.

Surveying the existing usage of this enqueue method, it's a common pattern that Reference::clear is called before or after enqueuing.
A pull request was submitted for review. URL: https://git.openjdk.java.net/jdk8u-ri/pull/5 Date: 2022-04-20 00:15:58 +0000

URL: http://hg.openjdk.java.net/jdk9/jdk9/jdk/rev/bc1bf2be03bc User: lana Date: 2017-03-15 14:49:32 +0000

URL: http://hg.openjdk.java.net/jdk9/dev/jdk/rev/bc1bf2be03bc User: mchung Date: 2017-03-09 15:42:25 +0000

FC Extension Request The proposed spec and implementation is low risk [1] as a follow-up spec change per JDK-8071507. I have looked at the existing usage of this enqueue method from Maven artifacts shows that Reference::clear is called either before or after calling Reference::enqueue as a pair. In addition, existing code polls the enqueued reference from a ReferenceQueue that is expected that the reference object may have been cleared. We expect that the compatibility risk should be low and existing applications being impacted by this change should be very low. `jdk.ref.disableClearBeforeEnqueue` system property is introduced to disable the new behavior in case an existing application is impacted by this change and need time to fix their code. The fix is ready and I expect to integrate by 3/15 or earlier. [1] http://cr.openjdk.java.net/~mchung/jdk9/webrevs/8175797/webrev.00/index.html