Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8169425

Values computed by a ClassValue should not strongly reference the ClassValue

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P3 P3
    • tbd
    • 9
    • core-libs
    • Cause Known

      A computed value produced by a ClassValue instance should not strongly refer to that instance, for example:

      class Holder {
        Object o;
        Holder(Object o) { this.o = o; }
      }

      class MyClassValue extends ClassValue<Holder> {
        Holder computerValue(Class<?> type) {
          return new Holder(this);
        }
      }

      In the current JDK implementation this will prevent classes from being garbage collected and therefore cause a memory link.

      Rather than changing the implementation of ClassValue to support such an edge case it is preferred to update the documentation of ClassValue.computeValue warning against such behaviour.

            psandoz Paul Sandoz
            psandoz Paul Sandoz
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: