JDK-8306039 : ParameterizedType.getOwnerType() documentation is incomplete about null result
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang:reflect
  • Affected Version: 8,11,17,20
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2023-04-15
  • Updated: 2024-11-04
  • Resolved: 2024-11-04
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 24
24Resolved
Related Reports
CSR :  
Duplicate :  
Relates :  
Description
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 ----------


Comments
Additional Information from submitter =========================== Regarding the second paragraph about the documentation for `AnnotatedParameterizedType.getAnnotatedOwnerType()` being misleading as well; that seems to also affect `AnnotatedType.getAnnotatedOwnerType()`. (It is also not completely obvious to me why back then this default method `getAnnotatedOwnerType()` was added to AnnotatedType instead of just AnnotatedParameterizedType, but that is probably a different topic, and cannot be solved now anymore.)
17-04-2023

The description in question can be found at: https://docs.oracle.com/en/java/javase/20/docs/api/java.base/java/lang/reflect/ParameterizedType.html#getOwnerType()
16-04-2023