Review Request JDK-8201793: (ref) Reference object should not support cloning
mandy chung
mandy.chung at oracle.com
Sat Apr 28 00:27:19 UTC 2018
On 4/28/18 6:08 AM, Kim Barrett wrote:
>> On Apr 26, 2018, at 10:16 AM, mandy chung <mandy.chung at oracle.com> wrote:
>>
>> The semantics of cloning a Reference object is not clearly defined. In addition, it is questionable whether it can be meaningfully supported in particular with concurrent reference processing.
>>
>> The reachability state of a Reference object may change during GC reference processing. The referent may have been cleared when it reaches its reachability state. In addition, it may be enqueued or pending for enqueuing. Cloning a Reference object with a referent that is unreachable but not yet cleared might mean to resurrect the referent. A cloned enqueued Reference object will never be enqueued. A Reference object cannot be meaningfully cloned.
>>
>> We propose Reference::clone to throw CloneNotSupportedException. To clone a Reference object, it should create a new instance via its constructor.
>>
>> CSR: https://bugs.openjdk.java.net/browse/JDK-8202260
>>
>> Webrev:
>> http://cr.openjdk.java.net/~mchung/jdk11/webrevs/8201793/webrev.00/
>>
>> Mandy
> The webrev doesn’t have the minor doc change suggested in the CSR.
I have that fixed in my local repo but the webrev was not updated.
diff --git a/src/java.base/share/classes/java/lang/ref/Reference.java
b/src/java.base/share/classes/java/lang/ref/Reference.java
--- a/src/java.base/share/classes/java/lang/ref/Reference.java
+++ b/src/java.base/share/classes/java/lang/ref/Reference.java
@@ -300,6 +300,20 @@
return this.queue.enqueue(this);
}
+ /**
+ * Throws {@link CloneNotSupportedException}. A {@code Reference}
cannot be
+ * meaningfully cloned. Construct a new {@code Reference} instead.
+ *
+ * @returns never returns normally
+ * @throws CloneNotSupportedException always
+ *
+ * @since 11
+ */
+ @Override
+ protected Object clone() throws CloneNotSupportedException {
+ throw new CloneNotSupportedException();
+ }
+
/* -- Constructors -- */
> Other than that, looks good.
>
Thanks.
Mandy
More information about the core-libs-dev
mailing list