JDK-8176389 : Release Note: java.lang.ref.Reference.enqueue method clears the reference object before enqueuing
  • Type: Sub-task
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 8u351,openjdk8u352,9
  • Priority: P4
  • Status: Closed
  • Resolution: Delivered
  • Submitted: 2017-03-08
  • Updated: 2022-09-16
  • Resolved: 2017-09-22
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 8 JDK 9
8u351Resolved 9Resolved
Description
`java.lang.ref.Reference.enqueue` method clears the reference object before it is added to the registered queue.  When the `enqueue` method is called, the reference object is cleared and `get()` method will return null in JDK 9.

Typically when a reference object is enqueued, it is expected that the reference object is cleared explicitly via the `clear` method to avoid memory leak because its referent is no longer referenced.  In other words the `get` method is expected not to be called in common cases once the `enqueue`method is called.  In the case when the `get` method from an enqueued reference object and existing code attempts to access members of the referent, `NullPointerException` may be thrown.  Such code will need to be updated.