Improve TypeVariable support

XMLWordPrintable

    • Type: CSR
    • Resolution: Approved
    • Priority: P2
    • 26
    • Component/s: core-libs
    • None
    • behavioral
    • minimal
    • Clients may rely on the same object being returned.
    • Java API
    • SE

      Summary

      Return a copy of an underlying object and change specification in TypeVariable::getGenericDeclaration from "returns the" to "returns a" so that it becomes allowed to return any representation of an object.

      Problem

      The TypeVaiableImpl held and returned the underlying object, and since Method and Constructor are mutable, mutating a returned object also mutated the internally held variable so that other callers would now see and share the same instance.

      Solution

      Create an internal copy of the underlying object and return it instead, updating the specification accordingly.

      Specification

      diff --git a/src/java.base/share/classes/java/lang/reflect/TypeVariable.java b/src/java.base/share/classes/java/lang/reflect/TypeVariable.java
      index 01746e3438508..d4ab4fccbb3e7 100644
      --- a/src/java.base/share/classes/java/lang/reflect/TypeVariable.java
      +++ b/src/java.base/share/classes/java/lang/reflect/TypeVariable.java
      @@ -72,7 +72,7 @@ public interface TypeVariable<D extends GenericDeclaration> extends Type, Annota
           Type[] getBounds();
       
           /**
      -     * Returns the {@code GenericDeclaration} object representing the
      +     * Returns a {@code GenericDeclaration} object representing the
            * generic declaration declared for this type variable.
            *
            * @return the generic declaration declared for this type variable.
       
       
      

            Assignee:
            Per-Ake Minborg
            Reporter:
            Per-Ake Minborg
            Chen Liang
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: