Re: WeakReference with null referent

2018-07-10 Thread Zheka Kozlov
There are a few valid use cases where `new WeakReference<>(null)` makes some sense. So, we shouldn't forbid nulls. `new WeakReference<>(null, queue)` makes less sense but I bet someone is using this too for some reason. My initial message was not about changing the behavior but only about changin

Re: WeakReference with null referent

2018-07-10 Thread mandy chung
On 7/10/18 4:04 PM, Éamonn McManus wrote: Do you know any other example? Here's an example from the JDK itself: http://hg.openjdk.java.net/jdk/jdk11/file/2a89e80301b1/src/java.desktop/share/classes/sun/font/Type1Font.java#l101 Thanks Eamonn. I also found a few other similar usages in JDK

Re: WeakReference with null referent

2018-07-10 Thread mandy chung
On 7/9/18 11:59 PM, Peter Levart wrote: There are situations where being able to create a XxxReference without a referent is useful. For example, imagine a doubly-linked list of WeakReference subclasses - a special instance without a referent can be used as the head of such list that neve

Re: WeakReference with null referent

2018-07-10 Thread Peter Levart
Hi Mandy, On 07/10/2018 12:18 AM, mandy chung wrote: On 7/9/18 12:59 PM, Per Liden wrote: On 2018-07-09 20:49, mandy chung wrote: On 7/9/18 11:31 AM, Zheka Kozlov wrote: It is possible to create a WeakReference/SoftReference/PhantomReference with a null value in which case the Reference

Re: WeakReference with null referent

2018-07-09 Thread Zheka Kozlov
I also created an issue in IDEA bug tracker: https://youtrack.jetbrains.com/issue/IDEA-195298. This at least should be handled by an IDE.

Re: WeakReference with null referent

2018-07-09 Thread mandy chung
On 7/9/18 12:59 PM, Per Liden wrote: On 2018-07-09 20:49, mandy chung wrote: On 7/9/18 11:31 AM, Zheka Kozlov wrote: It is possible to create a WeakReference/SoftReference/PhantomReference with a null value in which case the Reference will never be enqueued. This is quite obvious (since

Re: WeakReference with null referent

2018-07-09 Thread Roger Riggs
Hi, After so many years of accepting null, throwing NPE would an incompatible change and break existing uses. Documenting it as ill advised or useless is would be a useful caution. Regards, Roger On 7/9/18 3:59 PM, Per Liden wrote: On 2018-07-09 20:49, mandy chung wrote: On 7/9/18 11:31

Re: WeakReference with null referent

2018-07-09 Thread Per Liden
On 2018-07-09 20:49, mandy chung wrote: On 7/9/18 11:31 AM, Zheka Kozlov wrote: It is possible to create a WeakReference/SoftReference/PhantomReference with a null value in which case the Reference will never be enqueued. This is quite obvious (since null cannot be weakly/softly/phantom re

Re: WeakReference with null referent

2018-07-09 Thread mandy chung
On 7/9/18 11:31 AM, Zheka Kozlov wrote: It is possible to create a WeakReference/SoftReference/PhantomReference with a null value in which case the Reference will never be enqueued. This is quite obvious (since null cannot be weakly/softly/phantom reachable). But I think it's worth being menti