Top Description Fields Constructors Methods
org.graalvm.nativeimage

public final Class MissingReflectionRegistrationError

extends Error
Class Inheritance
Imports
java.io.Serial, java.lang.reflect.Constructor, .Field, .Method

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.

  1. 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.
  2. 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.

Since
23.0

Field Summary

Modifier and TypeField and Description
private final Class<?>
private final String
private final Class<?>
private final Class<?>[]
private static final long

Constructor Summary

AccessConstructor and Description
public
MissingReflectionRegistrationError(String message, Class<?> elementType, Class<?> declaringClass, String elementName, Class<?>[] parameterTypes)

Method Summary

Modifier and TypeMethod and Description
public Class<?>

Returns:

The class on which the missing query was tried, or null on static queries (e.g. Class#forName(String)).
getDeclaringClass
()

public String

Returns:

The name of the queried element, or bulk query method (e.g. "getMethods").
getElementName
()

public Class<?>

Returns:

The type of the element trying to be queried (Class, Method, Field or Constructor), or null if the query is a bulk query (like Class#getMethods()).
getElementType
()

public Class<?>[]

Returns:

The parameter types passed to the query, or null if the query doesn't take parameter types as argument.
getParameterTypes
()

Field Detail

declaringClassback to summary
private final Class<?> declaringClass
elementNameback to summary
private final String elementName
elementTypeback to summary
private final Class<?> elementType
parameterTypesback to summary
private final Class<?>[] parameterTypes
serialVersionUIDback to summary
private static final long serialVersionUID

Hides java.lang.Error.serialVersionUID.

Annotations
@Serial

Constructor Detail

MissingReflectionRegistrationErrorback to summary
public MissingReflectionRegistrationError(String message, Class<?> elementType, Class<?> declaringClass, String elementName, Class<?>[] parameterTypes)
Since
23.0

Method Detail

getDeclaringClassback to summary
public Class<?> getDeclaringClass()
Returns:Class<?>

The class on which the missing query was tried, or null on static queries (e.g. Class#forName(String)).

Since
23.0
getElementNameback to summary
public String getElementName()
Returns:String

The name of the queried element, or bulk query method (e.g. "getMethods").

Since
23.0
getElementTypeback to summary
public Class<?> getElementType()
Returns:Class<?>

The type of the element trying to be queried (Class, Method, Field or Constructor), or null if the query is a bulk query (like Class#getMethods()).

Since
23.0
getParameterTypesback to summary
public Class<?>[] getParameterTypes()
Returns:Class<?>[]

The parameter types passed to the query, or null if the query doesn't take parameter types as argument.

Since
23.0