A DESCRIPTION OF THE PROBLEM :
The documentation of ClassValue currently leaves some aspects unclear. See for example also https://stackoverflow.com/questions/7444420/classvalue-in-java-7 where users ask about the purpose of the class.
JDK-8352433 has already improved this to some extent.
Improvement suggestions (based on current JDK 25 doc):
- Explain why this class exists and why other approaches are inferior, for example (my understanding):
> Unlike a {@link ConcurrentHashMap ConcurrentHashMap<Class, ...>} or a {@link WeakHashMap WeakHashMap<Class, ...>} ClassValue does not prevent unloading of the Class used as key, even if the associated value has a direct or indirect strong reference to the Class.
- Explain how to use ClassValue (possibly also with a small example snippet), that is, subclass ClassValue and implement `computeValue`
- Explicitly mention that a ClassValue instance can be safely used by multiple threads; currently the documentation only hints at this (for example with "multiple invocations may happen under race")
- Make the documentation adjustments for JDK-8169425 (in case that still applies)
- Mention also in the `computeValue` documentation that it can end up being called multiple times under a race (currently this is only mentioned in the class doc)
The documentation of ClassValue currently leaves some aspects unclear. See for example also https://stackoverflow.com/questions/7444420/classvalue-in-java-7 where users ask about the purpose of the class.
Improvement suggestions (based on current JDK 25 doc):
- Explain why this class exists and why other approaches are inferior, for example (my understanding):
> Unlike a {@link ConcurrentHashMap ConcurrentHashMap<Class, ...>} or a {@link WeakHashMap WeakHashMap<Class, ...>} ClassValue does not prevent unloading of the Class used as key, even if the associated value has a direct or indirect strong reference to the Class.
- Explain how to use ClassValue (possibly also with a small example snippet), that is, subclass ClassValue and implement `computeValue`
- Explicitly mention that a ClassValue instance can be safely used by multiple threads; currently the documentation only hints at this (for example with "multiple invocations may happen under race")
- Make the documentation adjustments for JDK-8169425 (in case that still applies)
- Mention also in the `computeValue` documentation that it can end up being called multiple times under a race (currently this is only mentioned in the class doc)
- relates to
-
JDK-8169425 Values computed by a ClassValue should not strongly reference the ClassValue
-
- Open
-
-
JDK-8352433 Behavioral updates for ClassValue::remove
-
- Closed
-