JDK-8358966 : Improve ClassValue documentation
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.lang
  • Priority: P4
  • Status: New
  • Resolution: Unresolved
  • OS: generic
  • CPU: generic
  • Submitted: 2025-06-08
  • Updated: 2025-06-09
Related Reports
Relates :  
Relates :  
Description
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)