Skip to content

[GR-49770] Restrict the Expressivity of Patterns in resource-config.json #7487

@vjovanov

Description

@vjovanov

TL;DR

Native Image currently accepts Java regular expressions as file patterns in resource-config.json. This is problematic for two reasons:

  1. It is error-prone as users often miss simple patterns in resources: The errors are common due to wrongly written (or missing) \\Q and \\E characters.
  2. It is computationally demanding to check if a query that does not hit a resource should throw a MissingResourceRegistrationError or return a null. With regular expressions, it is necessary to check all regular expressions in the build against the current resource path.

In this proposal, we restrict the resource-matching patterns to a subset of the glob patterns to simplify pattern matching and reduce computational complexity. The patterns that would be supported are:

  1. The * pattern that matches any number of characters including none within the current directory.
  2. The ** as a name component to recursively match any number of layers of directories.

Proposed patterns allow users to write queries to bulk-include resources, for example, assets/**/* or images/**/*.png. However, they can be canonicalized into a tree-like structure that allows fast checking of negative queries at run time.

The new format will allow only the inclusion patterns:

{
  "resources": [
      {
        "glob": "assets/**"
      },
      {
        "module": "myJavaModule",
        "glob": "images/**/*.png"
      }
  ]
}

Goals

  1. Simplify resource patterns to make writing of resource patterns easier.
  2. Reduce the cost of run-time checks for negative resource queries.

Non-Goals

  1. Make resource-pattern writing harder.
  2. Disallow matching multiple resources with one entry in resource-config.json.

Backward Compatibility

The new format will be output by the agent and described in all documentation as the default. The reachability metadata will be migrated to the new format when the JDK 17 and JDK 21 version adopt the back-ported support for this feature.

The current format for resources will be supported until the majority of the ecosystem adopts the new format.

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Released

Relationships

None yet

Development

No branches or pull requests

Issue actions