This exception is thrown when a reflective query (such as
Class.getMethod(String, Class[])
) tries to access an element that was not
registered
for reflection in the program. When an element is not registered, the exception will be
thrown both for elements that exist and elements that do not exist on the given classpath.
The purpose of this exception is to easily discover unregistered elements and to assure that all
reflective operations for registered elements have the expected behaviour.
We distinguish between two types of reflective queries: bulk queries and individual queries.
- Bulk queries are methods like
Class.getFields()
which return a complete list of
corresponding elements. Those queries need to be explicitly registered for reflection in order to
be called. If that is not the case, a MissingReflectionRegistrationError
will be
thrown.
- Individual queries are methods like
Class.getField(String)
which return a single
element. Those queries will succeed (or throw the expected ReflectiveOperationException
if either the element was individually registered for reflection, or the corresponding bulk query
was registered for reflection. If that is not the case, a
MissingReflectionRegistrationError
will be thrown. Some individual queries, like
Class.forName(String)
, do not have a corresponding bulk query and as such need their
arguments to be individually registered for reflection in order to behave correctly.
Examples:
Registration:
"queryAllDeclaredMethods": true
declaringClass.getDeclaredMethods()
will succeed.
declaringClass.getDeclaredMethod("existingMethod")
will return the expected method.
declaringClass.getDeclaredMethod("nonexistentMethod")
will throw a
NoSuchMethodException
.
Registration:
"fields": [{"name": "registeredField"}, {"name":
"registeredNonexistentField"}]
declaringClass.getDeclaredFields()
will throw a
MissingReflectionRegistrationError
.
declaringClass.getField("registeredField")
will return the expected field.
declaringClass.getField("registeredNonexistentField")
will throw a
NoSuchFieldException
.
declaringClass.getField("unregisteredField")
will throw a
MissingReflectionRegistrationError
.
declaringClass.getField("unregisteredNonexistentField")
will throw a
MissingReflectionRegistrationError
.