Package org.graalvm.nativeimage
Class MissingReflectionRegistrationError
java.lang.Object
java.lang.Throwable
java.lang.Error
org.graalvm.nativeimage.MissingReflectionRegistrationError
- All Implemented Interfaces:
Serializable
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, aMissingReflectionRegistrationError
will be thrown. - Individual queries are methods like
Class.getField(String)
which return a single element. Those queries will succeed (or throw the expectedReflectiveOperationException
if either the element was individually registered for reflection, or the corresponding bulk query was registered for reflection. If that is not the case, aMissingReflectionRegistrationError
will be thrown. Some individual queries, likeClass.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.
"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
.- Since:
- 23.0
- See Also:
-
Constructor Summary
-
Method Summary
Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Constructor Details
-
Method Details
-
getElementType
- Returns:
- The type of the element trying to be queried (
Class
,Method
,Field
orConstructor
), or null if the query is a bulk query (likeClass.getMethods()
). - Since:
- 23.0
-
getDeclaringClass
- Returns:
- The class on which the missing query was tried, or null on static queries (e.g.
Class.forName(String)
). - Since:
- 23.0
-
getElementName
- Returns:
- The name of the queried element, or bulk query method (e.g.
"getMethods"
). - Since:
- 23.0
-
getParameterTypes
- Returns:
- The parameter types passed to the query, or null if the query doesn't take parameter types as argument.
- Since:
- 23.0
-