oracle/graal · warning · GraalError

Cannot look up %s annotation at Native Image runtime

Error message

Cannot look up %s annotation at Native Image runtime

What it means

JNI is a pure constants/declarations class for the JNI interface; its private constructor throws IllegalStateException to prevent instantiation. Reaching this exception requires reflection or a bean/serialization framework to bypass the private constructor. All members are static and meant to be referenced on the class itself.

Source

Thrown at compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/annotation/AnnotationValueSupport.java:193

        JavaType returnType = method.getSignature().getReturnType(container);
        ResolvedJavaType memberType;
        try {
            memberType = returnType.resolve(container);
        } catch (NoClassDefFoundError e) {
            return new MissingType(returnType.getName(), e);
        }
        return AnnotationValueParser.parseMemberValue(memberType, ByteBuffer.wrap(info.bytes()), info.constPool(), container);
    }

    /**
     * Gets the annotation value of type {@code annotationType} present on {@code annotated}. This
     * method must only be called in jargraal as it requires the ability convert a {@link Class}
     * value to a {@link ResolvedJavaType} value.
     */
    @LibGraalSupport.HostedOnly
    public static AnnotationValue getAnnotationValue(Annotated annotated, Class<? extends Annotation> annotationType) {
        if (inRuntimeCode()) {
            throw new GraalError("Cannot look up %s annotation at Native Image runtime", annotationType.getName());
        }
        boolean inherited = annotationType.getAnnotation(Inherited.class) != null;
        return getAnnotationValue0(annotated, annotationType, inherited);
    }

    /**
     * Looks for an entry in {@code values} whose {@linkplain AnnotationValue#getAnnotationType()
     * type} matches {@code annotationType}.
     *
     * @param container used to resolve type names in {@code values}
     */
    @LibGraalSupport.HostedOnly
    public static AnnotationValue findAnnotationValue(List<AnnotationValue> values, Class<? extends Annotation> annotationType, ResolvedJavaType container) {
        if (inRuntimeCode()) {
            throw new GraalError("Cannot look up %s annotation at Native Image runtime", annotationType.getName());
        }
        String internalName = "L" + annotationType.getName().replace(".", "/") + ";";
        for (var e : values) {

View on GitHub (pinned to a66e9ccd1d)

Solutions

  1. Reference JNI constants statically (JNI.JNI_OK, JNI.JNIEnv, ...) and never instantiate the class.
  2. Exclude org.graalvm.jniutils from classpath/bean scanning in your DI or serialization framework.
  3. Fix reflective test utilities to skip classes with private throwing constructors.
Defensive patterns

Strategy: validation

Prevention

When it happens

Trigger: Constructor.newInstance() on JNI via reflection; classpath-scanning DI or JSON frameworks (Jackson subtype scanning, Spring component scan with aggressive filters) attempting to instantiate every class in org.graalvm.jniutils.

Common situations: Framework auto-discovery sweeping the SDK jar; test utilities that instantiate all classes of a package; misuse of reflection helpers that ignore private visibility.

Related errors


AI-assisted analysis of oracle/graal@a66e9ccd1d (2026-08-14). Data as JSON: /api/errors/d13e85d2def71638. Report an issue: GitHub.