As reported by #28977
The ResourcePatternHints
is a container for includes
and excludes
and multiple ResourcePatternHints
can be registered. It's possible that callers may expect that these includes and excludes are related, however, when the JSON is written all excludes and all includes are included together. See ResourceHintsPredicates.AggregatedResourcePatternHints for an example of the flattening that needs to occur when using the pattern hints.
Comment From: bdshadow
I want to help with this, but please advise on what is expected. For example, let's say that we have the following resource hints:
ResourceHints hints = new ResourceHints();
hints.registerPattern(hint -> hint.includes("com/*").excludes("com/example/*"));
hints.registerPattern(hint -> hint.includes("com/example/*/all.properties").excludes("com/example/ignore/all.properties"));
Currently, it produces:
{
"resources": {
"includes": [
{ "pattern": "\\Q/\\E"},
{ "pattern": "\\Qcom/\\E.*"},
{ "pattern": "\\Qcom\\E"},
{ "pattern": "\\Qcom/example/\\E.*\\Q/all.properties\\E"},
{ "pattern": "\\Qcom/example\\E"}
],
"excludes": [
{ "pattern": "\\Qcom/example/\\E.*"},
{ "pattern": "\\Qcom/example/ignore/all.properties\\E"}
]
}
}
Am I right that it's supposed to be the following way:
{
"resources": {
"includes": [
{ "pattern": "\\Q/\\E"},
{ "pattern": "\\Qcom/\\E.*"},
{ "pattern": "\\Qcom\\E"},
],
"excludes": [
{ "pattern": "\\Qcom/example/\\E.*"},
{ "pattern": "\\Qcom/example/ignore/all.properties\\E"}
]
}
}
I think it can be quite complicated in some cases to filter it out properly. However, a simple filter is possible - for example, if it's the same or if a particular "include" is of a particular pattern of some "exclude" - then remove this "include".
Alsoб just for a note, here is the corresponding implementation in the graalvm: https://github.com/oracle/graal/pull/2912/files#diff-4b973ff5fd08418824ad1f4c7ce54a757b0641094f899f02a1c54fdc112739f2R263. It goes the same way as ResourceHintsPredicates.AggregatedResourcePatternHints, so making such filtering is better but not necessary. I meanб this ticket doesn't look like a bug to me (but probably, I'm missing smth).
Comment From: snicoll
@bdshadow you are correct. I think the assumption made in https://github.com/spring-projects/spring-framework/issues/28977 was wrong. I think @philwebb thought that you could register an array of includes/excludes pair but, looking at the documentation it really is an array of includes and an array of excludes.
As such, I believe the current behavior is correct based on that constraints. Thanks for bringing this up!
Comment From: philwebb
I think @philwebb thought that you could register an array of includes/excludes pair
No, I didn't think that, but I was worried that users might as include
and exclude
are on ResourcePatternHints
. I think I was thinking a ResourceHints.registerInclude
and ResourceHints.registerExclude
method might be better to show that includes/excludes are completely independent.
Given that the API is out there and nobody seems to have hit the issue it looks like my fears were unfounded.
Comment From: bclozel
Excludes will go away in #31340 as GraalVM will simplify support on the resource-config format.