Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GR-42114] Integrate missing resource metadata #7179

Closed

Conversation

graalvmbot
Copy link
Collaborator

This PR allows to throw MissingResourceRegistrationError when the metadata for a resource the user tries to access is not included in the image.

The goal is to match this proposal: https://github.com/graalvm/taming-build-time-initialization/blob/main/metadata-exceptions/Exceptions%20proposal.md.

Changes:

  • The main changes lies in Resources.java. We now use a map from a Module and a String to an Object instead of a ResourceStorageEntry. This allows to store a dummy object for negative queries, or an exception for resources and bundles that threw when accessed at build time.
    Accessing the map:

    • if we find an entry, we proceed as before and return it.
    • If we find an exception, we throw it.
    • If we find a negative query, we return null.
    • If there is no entry, we check all the patterns that were registered by the user and if one of them matches the queried resource, we return null. Otherwise, we throw a MissingResourceRegistrationError.
  • To avoid saving Regexes and increasing the image size, only a simple pattern matching is performed using the function matchResource. It only accepts exact matches, or matches with one .* anywhere in the pattern. If there are more than one .*, only the last one is used as a wildcard, while the others are treated as normal characters.

  • The agent now registers all resources and bundles encountered, even if it is null or caused an exception (see changes in BreakpointInterceptor.java). Those resources will be saved either as negative queries, or as exceptions that will be thrown at run time.

  • The LocalizationSupport now registers intermediate bundles for reflection and resource access. This is needed because, for example, when querying the bundle ResourceBundle_en_US, the bundles ResourceBundle and ResourceBundle_en are accessed by reflection and queried as well.

  • The NativeImageResourceFileSystem now differentiates inodes that are true resources from inodes that are created as placeholders (intermediate directories) or at run time (see NativeImageResourceFileSystem.java).

    • The first type of inodes are created from the registered resources and are accessed as normal resources, so trying to access this type of resource through the filesystem without registering it beforehand will throw a MissingResourceRegistrationError.
    • For the placeholder resources, they are not necessarily stored in the Resource map, as they are created by the filesystem from the full pathes of the resources. For this reason, those types of inodes do not fetch the Resources map, as it would often throw an unwanted MissingResourceRegistrationError.
    • Inodes created at run time are treated a bit differently. On a new inode creation, the Resources map is queried to check whether the resource was registered or not, but the outputted result is ignored. Hence, if a new inode is created, but the resource path was not registered beforehand, a MissingResourceRegistrationError is thrown.

@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Aug 10, 2023
@graalvmbot graalvmbot closed this Aug 11, 2023
@graalvmbot graalvmbot deleted the scoppey/GR-42114/integrate-missing-resource-metadata branch August 11, 2023 04:17
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.

3 participants