Class MissingReflectionRegistrationError

java.lang.Object
java.lang.Throwable
java.lang.Error
org.graalvm.nativeimage.MissingReflectionRegistrationError
All Implemented Interfaces:
Serializable

public final class MissingReflectionRegistrationError extends Error
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
See Also:
  • Constructor Details

    • MissingReflectionRegistrationError

      public MissingReflectionRegistrationError(String message, Class<?> elementType, Class<?> declaringClass, String elementName, Class<?>[] parameterTypes)
      Since:
      23.0
  • Method Details

    • getElementType

      public Class<?> getElementType()
      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()).
      Since:
      23.0
    • getDeclaringClass

      public Class<?> 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

      public String getElementName()
      Returns:
      The name of the queried element, or bulk query method (e.g. "getMethods").
      Since:
      23.0
    • getParameterTypes

      public Class<?>[] getParameterTypes()
      Returns:
      The parameter types passed to the query, or null if the query doesn't take parameter types as argument.
      Since:
      23.0