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

ParameterizedType.getOwnerType() documentation is incomplete about null result

XMLWordPrintable

      A DESCRIPTION OF THE PROBLEM :
      Currently the documentation for java.lang.reflect.ParameterizedType.getOwnerType() says:
      > If this type is a top-level type, null is returned.
      > ...
      > Returns: [...] If this type is a top-level type, null is returned

      Both sentences are incorrect, or at least incomplete. There are other cases where the result can be null, for example for local classes.

      Maybe the documentation from AnnotatedParameterizedType.getAnnotatedOwnerType() should be copied which seems to be more complete regarding when the result can be null. However, maybe the documentation for getAnnotatedOwnerType() is actually also wrong / misleading because there should not be any (Annotated)ParameterizedType for primitive types, void and anonymous types (for anonymous types only the generic supertype can be parameterized?), should there?




      ---------- BEGIN SOURCE ----------
      void test() {
          class Local<T> {}
          ParameterizedType paramType = (ParameterizedType) new Local<Integer>() {}.getClass().getGenericSuperclass();
          System.out.println(paramType);
          // Prints `null` as owner, even though the type is not a top-level type
          System.out.println("Owner type: " + paramType.getOwnerType());
      }
      ---------- END SOURCE ----------

            liach Chen Liang
            webbuggrp Webbug Group
            Votes:
            1 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: