JDK-8175797 : (ref) Reference::enqueue method should clear referent 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: 2019-01-02
  • 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 9
10Fixed 9 b161Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Sub Tasks
JDK-8176389 :  
Description
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.
Comments
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
08-03-2017