Skip to content

[GR-73955] Add error messages for unsatisfied run-time conditions.#13232

Open
graalvmbot wants to merge 1 commit intomasterfrom
vj/GR-73955-condition-errors
Open

[GR-73955] Add error messages for unsatisfied run-time conditions.#13232
graalvmbot wants to merge 1 commit intomasterfrom
vj/GR-73955-condition-errors

Conversation

@graalvmbot
Copy link
Copy Markdown
Collaborator

This PR improves missing-registration diagnostics when reachability metadata exists, but the matching entry is inactive because its runtime typeReached conditions are not satisfied.

Today those cases are often reported as if metadata were missing entirely. That is misleading for users because the required action is different: the fix may be to make an existing condition reachable at run time, not to add new metadata. The most
visible failure was resource lookup via ClassLoader::getResources / Resources.createURLs, but the same issue also showed up in reflection, dynamic proxies, serialization, and related runtime lookup paths.

What changed

  1. Missing-registration errors now distinguish between:

    • no matching metadata at all, and
    • matching metadata that exists but is currently inactive because its runtime conditions are unsatisfied.
  2. MissingReflectionRegistrationError, MissingResourceRegistrationError, and MissingSerializationRegistrationError now accept RuntimeDynamicAccessMetadata.

    • When matching metadata exists but is inactive, the error message now says that explicitly.
    • The message also includes the unsatisfied runtime conditions, so users can see why the metadata did not apply.
  3. Resource diagnostics were fixed end-to-end, with the primary fix in the ClassLoader::getResources / Resources.createURLs path.

    • Resource lookups now detect unsatisfied conditional registrations instead of treating them as plain “missing metadata”.
    • Hosted resource processing now records include patterns and glob registrations together with their conditions so runtime reporting can recover that context.
    • This also improves diagnostics for related resource access paths such as direct resource lookups and resource-bundle access.
  4. Reflection and class-query handling was tightened so condition checks happen consistently at runtime.

    • Class, field, method, constructor, array, and unsafe-allocation errors now report the associated conditional metadata when available.
    • Per-member dynamic-access metadata is attached to decoded AccessibleObjects, so invocation and field-access failures can report the correct inactive condition.
    • DynamicHub / ClassRegistries class-query paths were updated so name-based lookups and array-class access behave consistently when conditional reflection metadata is present but unsatisfied.
  5. Proxy diagnostics were improved in two ways.

    • Proxy lookups now report matching-but-unsatisfied metadata instead of falling back to a generic missing-registration error.
    • If a proxy registration exists with the same interfaces in a different order, the error now adds a targeted hint explaining that proxy interface order is significant.
  6. Serialization metadata propagation was tightened.

    • Serialization constructor-accessor metadata is now tracked separately and preserved through image-layer translation.
    • Runtime serialization failures can now report inactive conditional metadata instead of losing that context.
    • Record deserialization support was also tightened by registering the primitive extractor helpers used for primitive record components.
  7. A few internal reflection users were updated to match the stricter class-query behavior.

    • This keeps existing runtime behavior working in places that query declaring classes reflectively before accessing members.
  8. Added testing/debugging hooks for validating condition behavior.

    • -H:TrackConditionSatisfied=<fqcn|*> can be used to trace when a runtime typeReached condition becomes satisfied.
    • -H:+TrackReflectionClassQueryChecks provides concise tracing for reflection class-query checks.

Testing

  • Added serialization regression coverage for record deserialization, including primitive-component extractor paths.
  • Added proxy regression coverage for annotation proxy creation.

Examples

org.graalvm.nativeimage.MissingReflectionRegistrationError
 Cannot reflectively access method 'hello.conditionerrors.reflection.HelloReflection$HelloTarget#message()'.

 Reachability metadata for this access was found, but it is inactive because its runtime conditions were not satisfied.
 To fix this, either change/remove the metadata condition, or make sure the condition is reached before this access.
 Unsatisfied runtime conditions:

     "typeReached": "hello.conditionerrors.reflection.NeverReachedCondition"

 The matching metadata element in the 'reflection' section of 'reachability-metadata.json' is:

     {
       "type": "hello.conditionerrors.reflection.HelloReflection$HelloTarget"
     }

 The 'reachability-metadata.json' file should be located in 'META-INF/native-image/<group-id>/<artifact-id>/' of your project. For further help, see https://www.graalvm.org/latest/reference-manual/native-image/metadata/#reflection
com.oracle.svm.core.jdk.resources.MissingResourceRegistrationError
Cannot access resource from module 'null' at path 'hello-resource.txt'.

Reachability metadata for this access was found, but it is inactive because its runtime conditions were not satisfied.
To fix this, either change/remove the metadata condition, or make sure the condition is reached before this access.
Unsatisfied runtime conditions:

    "typeReached": "hello.conditionerrors.resource.NeverReachedCondition"

The matching metadata element in the 'resources' section of 'reachability-metadata.json' is:

    {
      "glob": "hello-resource.txt"
    }

The 'reachability-metadata.json' file should be located in 'META-INF/native-image/<group-id>/<artifact-id>/' of your project. For further help, see https://www.graalvm.org/latest/reference-manual/native-image/metadata/#resources
 com.oracle.svm.core.reflect.serialize.MissingSerializationRegistrationError
  Cannot serialize or deserialize 'hello.conditionerrors.serialization.HelloSerialization$HelloPayload'.

  Reachability metadata for this access was found, but it is inactive because its runtime conditions were not satisfied.
  To fix this, either change/remove the metadata condition, or make sure the condition is reached before this access.
  Unsatisfied runtime conditions:

      "typeReached": "hello.conditionerrors.serialization.NeverReachedCondition"

  The matching metadata element in the 'reflection' section of 'reachability-metadata.json' is:

      {
        "type": "hello.conditionerrors.serialization.HelloSerialization$HelloPayload",
        "serializable": true
      }

  The 'reachability-metadata.json' file should be located in 'META-INF/native-image/<group-id>/<artifact-id>/' of your project. For further help, see https://www.graalvm.org/latest/reference-manual/native-image/metadata/#reflection

@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Mar 28, 2026
@graalvmbot graalvmbot force-pushed the vj/GR-73955-condition-errors branch from 8c11eea to 87cf966 Compare March 28, 2026 22:01
  Thread RuntimeDynamicAccessMetadata through reflection, resource, and
  serialization lookup/reporting paths, and include unsatisfied runtime
  conditions in Missing*RegistrationError messages when matching metadata
  exists but conditions are not satisfied.

  Tighten condition-aware lookup behavior in DynamicHub/reflection paths,
  preserve serialization constructor-accessor metadata across image layers,
  add proxy interface-order hints for near matches, and fix
  createURLs/getResources missing-metadata reporting for unsatisfied
  resource include patterns (including globs). Also add a
  TrackConditionSatisfied testing option for condition transitions.
@graalvmbot graalvmbot force-pushed the vj/GR-73955-condition-errors branch from 87cf966 to 1dc1d2f Compare March 28, 2026 22:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

OCA Verified All contributors have signed the Oracle Contributor Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants