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-08-22
  • 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 Other
10Fixed 8u351Fixed 9 b161Fixed openjdk8u352Fixed
Related Reports
CSR :  
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
JDK 8u Fix Request: This fix is required for compliance with Java SE 8 Maintenance Release 4: https://jcp.org/en/jsr/detail?id=337
12-08-2022

A pull request was submitted for review. URL: https://git.openjdk.org/jdk8u-dev/pull/99 Date: 2022-08-11 19:12:23 +0000
11-08-2022

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
20-04-2022

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

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

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