JDK-8224243 : Add implSpec's to AccessibleObject and seal Executable
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang:reflect
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2019-05-20
  • Updated: 2022-06-16
  • Resolved: 2021-05-25
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 17
17 b24Fixed
Related Reports
Blocks :  
CSR :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
The spec https://download.java.net/java/early_access/jdk13/docs/api/java.base/java/lang/reflect/AccessibleObject.html#getAnnotation(java.lang.Class)
still says:
"Description copied from interface: AnnotatedElement
Returns this element's annotation for the specified type if such an annotation is present, else null."

In fact the following:
 new AccessibleObject() {}.getAnnotation(Deprecated.class);
leads to 
java.lang.AssertionError: All subclasses should override this method

same thing with
 new AccessibleObject() {}.getAnnotationsByType(Deprecated.class);

This (default) behavior deserves to be specified for example with @implSpec

     * @implSpec
     * This default implementation throws {@code AssertionError}. 


Comments
Changeset: 0b773593 Author: Joe Darcy <darcy@openjdk.org> Date: 2021-05-25 18:04:47 +0000 URL: https://git.openjdk.java.net/jdk/commit/0b7735938407fad5c2dbfb509d2d47bf172305e9
25-05-2021

Google Guava is known to extend AccessibleObject, there may be others.
20-05-2021

Will re-evaluate after eventual non-preview sealed class work, see JDK-8260514 (sequel to JEP 397, JDK-8246775).
29-03-2021

Conceptually, AccessibleObject is a sealed class. If it were re-declared to be a sealed class, once that language feature is available, the spec issue would be side-stepped.
20-07-2020

The protected constructor of AccessibleObject notes "Constructor: only used by the Java Virtual Machine." The two public subclasses of AccessibleObject, java.lang.reflect.Executable and java.lang.reflect.Field, do have overrides for both the methods in question. Therefore, the only way for the AssertionError code to be execution would be for a user-defined subclass of AccessibleObject, which is outside of the class's stated contract. Closing as will not fix.
20-05-2019